获取表的相关信息Sqlserver
2007-02-14 14:24
246 查看
SELECT tableName, colOrder, colName, IsIdentity, pKey, type, bits, length, digit, IsNullAble, defaultValue, memo,ltrim(rtrim(tableName))+'.'+ltrim(rtrim(colName)) as col from
(
SELECT
d.name as tableName,
a.colorder as colOrder,
a.name as colName,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 1 else 0 end) as 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 1 else 0 end) pKey,--0:不是,1:是
b.name type,--数据类型
a.length bits,--字节数
COLUMNPROPERTY(a.id,a.name,'PRECISION') as length,--长度
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as digit,--小数位数
(case when a.isnullable=1 then 0 else 1 end) as IsNullAble,--允许空0:允许,1:不允许
isnull(e.text,'') defaultValue,--默认值
isnull(g.[value],'') AS memo--字段说明
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 sysproperties g on a.id=g.id and a.colid = g.smallid
) as SystemInfo
(
SELECT
d.name as tableName,
a.colorder as colOrder,
a.name as colName,
(case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 1 else 0 end) as 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 1 else 0 end) pKey,--0:不是,1:是
b.name type,--数据类型
a.length bits,--字节数
COLUMNPROPERTY(a.id,a.name,'PRECISION') as length,--长度
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as digit,--小数位数
(case when a.isnullable=1 then 0 else 1 end) as IsNullAble,--允许空0:允许,1:不允许
isnull(e.text,'') defaultValue,--默认值
isnull(g.[value],'') AS memo--字段说明
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 sysproperties g on a.id=g.id and a.colid = g.smallid
) as SystemInfo
相关文章推荐
- SqlServer如何通过SQL语句获取处理器(CPU)、内存(Memory)、磁盘(Disk)以及操作系统相关信息
- SqlServer如何通过SQL语句获取处理器(CPU)、内存(Memory)、磁盘(Disk)以及操作系统相关信息
- Servlet Request对象 获取服务器的相关信息
- 获取ACCESS相关信息
- android获取手机相关信息大全
- wxWidgets获取本机IP,计算机名等相关信息 推荐
- PHP 手机浏览器访问网站获取手机相关信息方法集锦
- Android获取系统相关的信息
- Android下使用TelephonyManager类获取设备电话相关信息
- iOS 设备获取设备相关信息
- 获取Java系统相关信息
- 获取所有部门中当前员工薪水最高的相关信息,给出dept_no, emp_no以及其对应的salary
- PHP获取系统相关信息
- 获取XML中的相关信息的相关代码
- 根据经纬度获取所在城市的相关信息以及根据地点城市获取经纬度
- iphone开发之通过unix系统底层获取和系统相关的硬件信息
- Java 获取当前线程的相关信息
- 网站分类前导:获取网站标题和描述及对相关信息进行分词处理
- [Windwos Phone 7] 获取设备相关信息
- PHP获取客户端,PHP获取服务器相关信息