SQLSERVER查询所有数据库名,表名,和字段名的语句1.获取所有数据库名:
SELECT Name FROM Master..SysDatabases ORDER BY Name
2.获取所有表名:
SELECT Name FROM DatabaseName..SysObjects Where XType='U' ORDER BY Name
XType='U':表⽰所有⽤户表;
XType='S':表⽰所有系统表;
3.获取所有字段名:
SELECT Name FROM SysColumns WHERE id=Object_Id('TableName')
获取所有的字段表名中⽂统计显⽰可利⽤Navicat导出Excel:
SELECT
表名 = case lorder = 1 then d.name else'' end,
表说明 = case lorder = 1 then isnull(f.value, '') else'' end,
字段序号 = a.colorder,
字段名 = a.name,
标识 = case when COLUMNPROPERTY(a.id, a.name, 'IsIdentity')= 1 then '√'else'' end,
主键 = 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,
占⽤字节数 = a.length,
长度 = COLUMNPROPERTY(a.id, a.name, 'PRECISION'),
⼩数位数 = isnull(COLUMNPROPERTY(a.id, a.name, 'Scale'), 0),
允许空 = case when a.isnullable = 1 then '√'else'' end,
默认值 = , ''),
字段说明 = isnull(g.[value], '')
FROM
博客名syscolumns a
left join
systypes b
on
a.xusertype =
b.xusertype
inner join
sysobjects d
on
a.id = d.id pe = 'U' and d.name <> 'dtproperties'
left join
syscomments e
on
a.cdefault = e.id
left join
on
a.id = G.major_id lid = g.minor_id
left join
on
d.id = f.major_id and f.minor_id = 0
where
d.name = 'tablename'--如果只查询指定表,加上此where条件,tablename是要查询的表名;去除where条件查询所有的表信息
order by
a.lorder
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论