SQL2005查询表结构的SQL语句使用分享
时间:2024-01-15 21:47:52
SELECT
(case when a.colorder=1 then d.name else '' end) as 表名,--如果表名相同就返回空 syscolumns(表字段信息表) a sysobjects d
a.colorder as 字段序号,
a.name as 字段名,
(case when COLUMNPROPERTY( a.id,a.name, 'IsIdentity' )=1 then '√' else '' end) as 标识, --返回IsIdentity的值,IsIdentity只有两个值:0、1
(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) as 主键,--查询主键END
b.name as 类型, --systypes b
a.length as 占用字节数,
COLUMNPROPERTY(a.id,a.name,'PRECISION' ) as 长度,
isnull(COLUMNPROPERTY(a.id,a.name,'Scale' ),0) as 小数位数,
(case when a.isnullable=1 then '√' else '' end) as 允许空,
isnull(e.text,'' ) as 默认值, --syscomments e
isnull(g.[value],'' ) AS 字段说明 --sys.extended_properties g (字段信息表)
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 sys.extended_properties g
on a.id=g.major_id AND a.colid = g.minor_id
where d.name='systempara' --所要查询的表
order by a.id,a.colorder
标签:SQL2005,查询表结构
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python接口测试返回数据为字典取值方式
2021-09-27 07:37:00
![](https://img.aspxhome.com/file/2023/8/97668_0s.png)
python实现健康码查验系统
2022-06-27 06:31:34
![](https://img.aspxhome.com/file/2023/3/97613_0s.jpg)
Python Web框架Tornado运行和部署
2021-04-14 09:17:57
mysql 5.7.23 winx64解压版安装教程
2024-01-26 01:41:09
SQL Server查询结果导出到EXCEL表格的图文教程
2024-01-23 10:40:22
![](https://img.aspxhome.com/file/2023/4/96224_0s.jpg)
Golang并发读取文件数据并写入数据库的项目实践
2024-01-29 07:22:50
php返回相对时间(如:20分钟前,3天前)的方法
2023-10-26 11:20:38
Python绘图示例程序中的几个语法糖果你知道吗
2021-01-18 17:15:25
![](https://img.aspxhome.com/file/2023/7/127127_0s.jpg)
在ASP处理程序时,进度显示
2008-08-04 13:27:00
一些sql语句
2009-04-10 18:36:00
JavaScript 浮动定位提示效果实现代码第1/2页
2023-07-22 23:26:19
![](https://img.aspxhome.com/file/2023/5/55945_0s.jpg)
Javascript 中 String.replace( ) 的妙用
2008-08-05 18:08:00
Yolov5更换BiFPN的详细步骤总结
2023-01-17 02:51:22
![](https://img.aspxhome.com/file/2023/6/84056_0s.jpg)
Go位集合相关操作bitset库安装使用
2024-05-09 14:57:22
MySQL插入中文不乱码的5种方法
2024-01-17 10:47:21
Mysql5.7服务无法启动的图文解决教程
2024-01-29 03:44:39
![](https://img.aspxhome.com/file/2023/5/119715_0s.jpg)
一文彻底理清session、cookie、token的区别
2024-01-02 06:16:29
![](https://img.aspxhome.com/file/2023/6/132376_0s.jpg)
Tornado Web Server框架编写简易Python服务器
2021-10-18 09:23:52
mysql 控制台程序的提示符 prompt 字符串设置
2024-01-26 01:42:11
不同浏览器空格的宽度
2007-08-22 08:29:00
![](https://img.aspxhome.com/file/UploadPic/20078/22/200782283622920s.gif)