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 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 sysproperties g on a.id=g.id
and a.colid=g.smallid
order by a.id,a.colorder
SQL2005 :
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 PARENT_OBJ=A.ID 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.XUSERTYPE=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
ORDER BY
A.ID,A.COLORDER
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/390618/viewspace-995639/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/390618/viewspace-995639/