SqlServer查询所有表结构信息
SELECT TableName = CASE WHEN A.colorder = 1 THEN D.name ELSE '' END, PrimaryKey = 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, 'Column Name' = A.name, 'Data Type' = UPPER(B.name), 'Length' = CASE WHEN A.length = -1 THEN 'MAX' ELSE CONVERT(NVARCHAR(100), A.length) END, 'Precision' = CASE WHEN COLUMNPROPERTY(A.id, A.name, 'PRECISION') = -1 THEN 0 ELSE CONVERT(NVARCHAR(100), A.length) END, 'Scale' = ISNULL(COLUMNPROPERTY(A.id, A.name, 'Scale'), 0), 'Allow Null' = CASE WHEN A.isnullable = 1 THEN 'Y' ELSE 'N' END, 'Default' = '', 'IsIdentity' = CASE WHEN COLUMNPROPERTY(A.id, A.name, 'IsIdentity') = 1 THEN 'Y' ELSE 'N' END, 'Desc.' = '' 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 --WHERE D.name = 'PartBackList' ORDER BY A.id, A.colorder;
Newd
版权声明
作者:も不秃不秃
地址:https://www.cnblogs.com/Newd/p/14235383.html
© Newd 尊重知识产权,引用请注出处
广告位
(虚位以待,如有需要请私信)