1 USE database1
2 SELECT
3 表名 = CASE a.colorder WHEN 1 THEN c.name ELSE '' END,
4 序 = a.colorder,
5 欄位名 = a.name,
6 標識 = CASE COLUMNPROPERTY(a.id,a.name,'IsIdentity') WHEN 1 THEN '√' ELSE '' END,
7 主鍵 = CASE
8 WHEN EXISTS (
9 SELECT *
10 FROM sysobjects
11 WHERE xtype='PK' AND name IN (
12 SELECT name
13 FROM sysindexes
14 WHERE id=a.id AND indid IN (
15 SELECT indid
16 FROM sysindexkeys
17 WHERE id=a.id AND colid IN (
18 SELECT colid
19 FROM syscolumns
20 WHERE id=a.id AND name=a.name
21 )
22 )
23 )
24 )
25 THEN '√'
26 ELSE ''
27 END,
28 類型 = b.name,
29 位元組數 = a.length,
30 長度 = COLUMNPROPERTY(a.id,a.name,'Precision'),
31 小數 = CASE ISNULL(COLUMNPROPERTY(a.id,a.name,'Scale'),0)
32 WHEN 0 THEN ''
33 ELSE CAST(COLUMNPROPERTY(a.id,a.name,'Scale') AS VARCHAR)
34 END,
35 允許空 = CASE a.isnullable WHEN 1 THEN '√' ELSE '' END,
36 預設值 = ISNULL(d.[text],''),
37 說明 = ISNULL(e.[value],'')
38 FROM syscolumns a
39 LEFT JOIN systypes b ON a.xtype=b.xusertype
40 INNER JOIN sysobjects c ON a.id=c.id AND c.xtype='U' AND c.name<>'dtproperties'
41 LEFT JOIN syscomments d ON a.cdefault=d.id
42 LEFT JOIN sysproperties e ON a.id=e.id AND a.colid=e.smallid
43 ORDER BY c.name, a.colorder