⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tool_select_fetchstruct.sql

📁 根据表名提取表的结构包括表和字段的各种信息
💻 SQL
字号:
--数据库结构提取SQL语句
--2008.05.19

select
 (case when a.colorder=1 then d.name else '' end) N'表名',
 a.colorder N'字段序号',
 a.name N'字段名',
 (case when columnproperty( a.id,a.name,'IsIdentity')=1 then '√'else ''
end) N'标识',
 (case when (select count(*)
 from sysobjects
 where (name in
           (select name
          from sysindexes
          where (id = a.id) AND (indid in
                    (select indid
                   from sysindexkeys
                   where (id = a.id) AND (colid in
                             (select colid
                            from syscolumns
                            where (id = a.id) AND (name = a.name))))))) AND
        (xtype = 'PK'))>0 then '√' else '' end) N'主键',
 b.name N'类型',
 a.length N'占用字节数',
 columnproperty(a.id,a.name,'PRECISION') as N'长度',
 isnull(columnproperty(a.id,a.name,'Scale'),0) as N'小数位数',
 (case when a.isnullable=1 then '√'else '' end) N'允许空',
 isnull(e.text,'') N'默认值',
 isnull(g.[value],'') AS N'字段说明'
from  syscolumns  a 
left join systypes b
 on  a.xtype=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 sysproperties g
 on a.id=g.id AND a.colid = g.smallid
order by object_name(a.id),a.colorder

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -