SqlServer query the database for all table names, and table fields Detailed Description

TABLE SELECT name = d.name,
       table illustrates = isnull (f.value, '') ,
       ordering number = a.colorder,
       column name = a.name,
       Column Description = isnull (g. [Value] , ''),
       identity column = case when COLUMNPROPERTY (a.id, a.name , 'IsIdentity') = 1 then 1 else 0 end,
       the primary key column = 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 1 else 0 end,
       column type = b.name,
       the number of bytes = a. length,
       column length = COLUMNPROPERTY (a.id, a.name, ' PRECISION'),
       decimal = isnull (COLUMNPROPERTY (a.id, a.name , 'Scale'), 0),
       allowed to air = case when a. isnullable = 1 then 1 else 0 end ,
       default value = isnull (e.text,'')
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 表名称 ASC,排序号 ASC

Guess you like

Origin www.cnblogs.com/yujian90/p/11803147.html