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
发布评论