加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQLSERVER 2008 如何获取一个数据库中的所有表的名称、一个表中

发布时间:2020-12-12 13:43:38 所属栏目:MsSql教程 来源:网络整理
导读:1.查询数据库中的所有数据库名: SELECT Name FROM Master..SysDatabases ORDER BY Name 2.查询某个数据库中所有的表名: FROM SysObjects Where XType = ' U ' 3.查询表结构信息: 1 SELECT ( case when a.colorder = 1 then d.name else null end ) 表名,

1.查询数据库中的所有数据库名:

 SELECT Name FROM Master..SysDatabases ORDER BY Name

2.查询某个数据库中所有的表名:

FROM SysObjects Where XType='U' 3.查询表结构信息:

复制代码

 1 SELECT (case when a.colorder=1 then d.name else null end) 表名, 2 a.colorder 字段序号,a.name 字段名,128); line-height:1.5!important"> 3 (when COLUMNPROPERTY( a.id,a.name,IsIdentity')then 'else '' end) 标识,128); line-height:1.5!important"> 4 (when (SELECT count(*) FROM sysobjects  
 5 WHERE (name in (SELECT name FROM sysindexes  
 6 WHERE (id = a.id) AND (indid in  
 7 (SELECT indid FROM sysindexkeys  
 8 AND (colid  9 (SELECT colid FROM syscolumns AND (name = a.name)))))))  
10 AND (xtype = PK'))>0 end) 主键,b.name 类型,a.length 占用字节数,128); line-height:1.5!important">11 COLUMNPROPERTY(a.id,0); line-height:1.5!important">PRECISION') as 长度,128); line-height:1.5!important">12 isnull(Scale'),0) as 小数位数,(when a.isnullableend) 允许空,128); line-height:1.5!important">13 isnull(e.text,0); line-height:1.5!important">'') 默认值,255); line-height:1.5!important">isnull(g.[value],0); line-height:1.5!important">' AS 说明]
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' and d.name<>dtproperties' 
17 join syscomments e on a.cdefault=e.id  
18 join sys.extended_properties g =g.major_id AND a.colid=g.minor_id
19 join sys.extended_properties f on d.id=f.class and f.minor_id0
20 where b.name is not null
21 --WHERE d.name='要查询的表' --如果只查询指定表,加上此条件
22 order by a.id,a.colorder

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读