SQL Server 导出表格结构到excel中

很简单只需四步

第一步:安装Navicat

第二步:建立和SQLServer的链接

第三步:将下列代码放到相应数据库下执行

SELECT
     表名       = Case When A.colorder=1 Then D.name Else '' End,
     字段名     = A.name,
     主键       = 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,
     类型       = B.name,
     长度       = COLUMNPROPERTY(A.id,A.name,'PRECISION'),
     小数位数   = isnull(COLUMNPROPERTY(A.id,A.name,'Scale'),0),
     允许空     = Case When A.isnullable=1 Then '√'Else '' End,
     默认值     = 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
     A.id,A.colorder

第四步:将结果全选,copy到excel文件中即可

你可能感兴趣的:(SQL Server 导出表格结构到excel中)