1 2 ALTER proc [dbo].[test_queryTableInfo] 3 ( 4 @tableName varchar(200) 5 ) 6 as 7 begin 8 SELECT 9 表名=CASE WHEN a.colorder = 1 THEN d.name ELSE '' END, 10 表说明=CASE WHEN a.colorder = 1 THEN isnull(f.value, '') ELSE '' END , 11 字段序号=a.colorder , 12 字段名=a.name , 13 标识=CASE WHEN COLUMNPROPERTY(a.id, a.name, 'IsIdentity') = 1 THEN '√' ELSE '' END , 14 主键=CASE WHEN EXISTS ( 15 SELECT 1 16 FROM dbo.sysindexes si 17 INNER JOIN dbo.sysindexkeys sik ON si.id = sik.id AND si.indid = sik.indid 18 INNER JOIN dbo.syscolumns sc ON sc.id = sik.id AND sc.colid = sik.colid 19 INNER JOIN dbo.sysobjects so ON so.name = so.name AND so.xtype = 'PK' 20 WHERE sc.id = a.id AND sc.colid = a.colid) THEN '√' 21 ELSE '' 22 END , 23 外键=CASE WHEN tony.fkey is not null and tony.fkey=a.colid THEN '√' ELSE '' END , 24 外键表=CASE WHEN tony.fkey is not null and tony.fkey=a.colid 25 THEN object_name(tony.fkeyid) ELSE '' 26 END , 27 外键字段=CASE WHEN tony.fkey is not null and tony.fkey=a.colid 28 THEN (SELECT name FROM syscolumns 29 WHERE colid=tony.fkey AND id=tony.fkeyid) 30 ELSE '' 31 END, 32 类型=b.name , 33 长度=a.length , 34 精度=COLUMNPROPERTY(a.id, a.name, 'PRECISION') , 35 小数位数=ISNULL(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0) , 36 允许空=CASE WHEN a.isnullable = 1 THEN '√' ELSE '' END , 37 默认值= ISNULL(e.text, ''), 38 字段说明=ISNULL(g.[value], ''), 39 创建时间=d.crdate, 40 更改时间=CASE WHEN a.colorder = 1 THEN d.refdate ELSE NULL END 41 FROM dbo.syscolumns a 42 LEFT JOIN dbo.systypes b ON a.xtype = b.xusertype 43 INNER JOIN dbo.sysobjects d ON a.id = d.id AND d.xtype = 'U' AND d.status >= 0 44 LEFT JOIN dbo.syscomments e ON a.cdefault = e.id 45 LEFT JOIN sys.extended_properties g ON a.id = g.major_id AND a.colid = g.minor_id 46 LEFT JOIN sys.extended_properties f ON d.id = f.major_id AND f.minor_id = 0 47 LEFT JOIN sysobjects htl ON htl.parent_obj=d.id AND d.xtype='F' 48 LEFT JOIN sysforeignkeys tony on htl.id=tony.constid 49 WHERE d.name=@tableName --这里输入包含表名称的条件 50 ORDER BY d.id, a.colorder 51 end 52 53 GO