SQL语句查询表结构
时间:2021-07-01 10:21:17
帮助过:185人阅读
查询非系统数据库
Select name
FROM Master.. SysDatabases
where dbid
>4
-- 选择water数据库下的所有表
use [water] SELECT name
FROM sysobjects
WHERE xtype
= ‘U‘ Or xtype
= ‘S‘
-- 选择water数据库下的所有用户表
use [water] SELECT name
FROM sysobjects
WHERE xtype
= ‘U‘ AND OBJECTPROPERTY (id,
‘IsMSShipped‘)
= 0
-- 查询water数据库下的admin表的字段名,长度,类型,字段说明
use [water] SELECT a.
[name] as ‘字段名‘,a.length
‘长度‘,c.
[name] ‘类型‘,e.value
as ‘字段说明‘ FROM syscolumns a
left join systypes b
on a.xusertype
=b.xusertype
left join systypes c
on a.xtype
= c.xusertype
inner join sysobjects d
on a.id
=d.id
and d.xtype
=‘U‘
left join sys.extended_properties e
on a.id
= e.major_id
and a.colid
= e.minor_id
and e.name
=‘MS_Description‘
where d.name
=‘admin‘
其中sys.extended_properties系统内置视图用于存储字段说明,且只有在MSSQL2005以上才有这张表的,且前面的sys.不能去掉,SQL2000的话字段说明是存在另一个张表里的,表名忘记了,反正我不需要也懒得去查了...
特此记录!!!
SQL语句查询表结构
标签:表结构 title value color 类型 文档 hive water nan