SQL Server 输出所有表结构

 1 SELECT
 2   表名 = case when a.colorder=1 then d.name else '' end,
 3   表说明 = case when a.colorder=1 then isnull(f.value,'') else '' end,
 4   字段中文名称 = isnull(g.[value],''),
 5   字段英文名称 = a.name,
 6   类型 = b.name,
 7   长度 = COLUMNPROPERTY(a.id,a.name,'PRECISION'),
 8   主键 = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in(
 9   SELECT name FROM sysindexes WHERE indid in(
10   SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid 
11   ))) then '' else '' end,
12   默认值=isnull(e.text,''),
13   允许空=case when a.isnullable=1 then ''else '' end
14   FROM syscolumns a 
15   left join systypes b on a.xtype=b.xusertype 
16   inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
17   left join syscomments e on a.cdefault=e.id 
18   left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id  
19   left join sys.extended_properties f on d.id=f.major_id and f.minor_id =0 
20   where d.name='Tabl'
21   order by a.id,a.colorder
原文地址:https://www.cnblogs.com/CNQCJ/p/7145321.html