SQL SERVER 查看表说明,字段属性

查询表字段属性,说明等:

SELECT
表名=case when a.colorder=1 then d.name else '' end,
表说明=case when a.colorder=1 then isnull(f.value,'') else '' end,
字段序号=a.colorder,
字段名=a.name,
标识=case when COLUMNPROPERTY(a.id,a.name,'IsIdentity')=1 then '√'else '' end,
主键=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (
  SELECT name FROM sysindexes WHERE indid in(
   SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid
   ))) then '√' else '' end,
类型=b.name,
占用字节数=a.length,
长度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),
小数位数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
允许空=case when a.isnullable=1 then '√'else '' end,
默认值=isnull(e.text,''),
字段说明=isnull(g.[value],'')
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id
left join sys.extended_properties f on d.id=f.major_id and f.minor_id =0
where d.name='表名' --表名
order by a.id,a.colorder

只查询表字段说明:

SELECT
    表名 = OBJECT_NAME(c.object_id),
    字段名称 = c.name,
    字段说明 = ex.value
FROM
    sys.columns c
LEFT OUTER JOIN
    sys.extended_properties ex
ON
    ex.major_id = c.object_id
    AND ex.minor_id = c.column_id
    AND ex.name = 'MS_Description'
WHERE
    OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0
     AND OBJECT_NAME(c.object_id) = 'table_1'  -- 这里加上你的表名字

查询表在那个数据库:

exec sp_MSforeachdb @command1='USE ? if exists(SELECT 1 from sysobjects where id=object_id(''MemberInfo'')) PRINT ''?'''

查询字段在那些表:

select 
sysobjects.name as tablename,
syscolumns.name as columnname
from syscolumns
join sysobjects on sysobjects.id = syscolumns.id
where syscolumns.name like '%ProductEntryId%'

查询字段在那些存储过程中:

SELECT obj.Name 存储过程名,
  sc.TEXT 存储过程内容  
 FROM syscomments sc  
 INNER JOIN sysobjects obj ON sc.Id = obj.ID  
 WHERE sc.TEXT LIKE '%' + '字段名' + '%'  
 AND TYPE = 'P' 

你可能感兴趣的:(SQL SERVER 查看表说明,字段属性)