日期:2014-05-17 浏览次数:20467 次
SELECT
[表名]=CASE WHEN T.column_id = 1 THEN OBJECT_NAME(T.object_id) ELSE '' END ,
[字段编号]=T.column_id,
[字段名]=T.name,
[主键]=case when exists(SELECT 1 FROM sys.key_constraints where type='PK' and object_id=T.OBJECT_ID) THEN '●' ELSE '' END,
[标识列]=CASE T.is_identity WHEN 1 THEN '●' ELSE '' END,
[计算列]=CASE T.is_computed WHEN 1 THEN '●' ELSE '' END,
[字段类型]=(SELECT name FROM sys.types WHERE user_type_id = T.user_type_id),
[字段长度]= T.PRECISION,
[小数位] = T.Scale,
[允许空] = CASE T.is_nullable WHEN 1 THEN '●' ELSE '' END,
[默认值]= ISNULL((SELECT definition from sys.default_constraints where object_id = T.default_object_id),''),
[字段说明]=(SELECT VALUE FROM sys.extended_properties WHERE major_id = T.OBJECT_ID AND minor_id =T.column_id)
FROM sys.COLUMNS T
INNER JOIN sys.objects O ON T.object_id = O.object_id AND O.type = 'U'
WHERE RIGHT(OBJECT_NAME(T.object_id),3) <> 'Log' AND OBJECT_NAME(T.object_id) <>'AuditDDLEvents' AND OBJECT_NAME(T.object_id) <>'dtproperties'
ORDER BY OBJECT_NAME(T.object_id),T.column_id
--百度应有尽有,刚学到的
SELECT
表名=case when a.colorder=1 then d.name 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&nb