读取sql server表的字段名,字段类型,字段长度,字段属性描述的sql语句
2010-04-19 18:39
405 查看
读取sql server表的字段名,字段类型,字段长度,字段属性描述的sql语句
http://hi.baidu.com/jiaowei051/blog/item/a2256efdefe224f4fc037f0a.html
--方法一
SELECT [name] = a.name, [type_name] = b.name, length = a.prec, [description] = isnull(g.[value], ' ') FROM syscolumns a left join systypes b on a.xusertype=b.xusertype left join sysproperties g on a.id=g.id and a.colid=g.smallid where a.id=object_id( tablename') --如果只查询指定表,加上此条件 order by a.id,a.colorder
--下面的代码同样可以读取表的字段,字段类型和字段长度代码
select name,type_name,a.prec
from syscolumns a ,master.dbo.spt_datatype_info b
where id = object_id(N'tableName') and OBJECTPROPERTY(id, N'IsUserTable') =1 and a.xtype=b.ss_dtype
and a.length = isnull(b.fixlen, a.length) AND isnull(b.AUTO_INCREMENT,0) =
isnull(ColumnProperty (a.id, a.name, 'IsIdentity'),0) AND (b.ODBCVer is null or b.ODBCVer = 2)
以上在sql 2000中测试通过
这一句更强 (来自网上)
SELECT a.name 字段名,COLUMNPROPERTY(a.id,a.name,'IsIdentity') 标识,
(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) 主键,
b.name 类型,
COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
(case when a.isnullable=1 then '1'else '0' end) 允许空,
isnull(g.[value],'') AS 字段说明
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
where d.name = 'rsk'
order by a.id,a.colorder
http://hi.baidu.com/jiaowei051/blog/item/a2256efdefe224f4fc037f0a.html
--方法一
SELECT [name] = a.name, [type_name] = b.name, length = a.prec, [description] = isnull(g.[value], ' ') FROM syscolumns a left join systypes b on a.xusertype=b.xusertype left join sysproperties g on a.id=g.id and a.colid=g.smallid where a.id=object_id( tablename') --如果只查询指定表,加上此条件 order by a.id,a.colorder
--下面的代码同样可以读取表的字段,字段类型和字段长度代码
select name,type_name,a.prec
from syscolumns a ,master.dbo.spt_datatype_info b
where id = object_id(N'tableName') and OBJECTPROPERTY(id, N'IsUserTable') =1 and a.xtype=b.ss_dtype
and a.length = isnull(b.fixlen, a.length) AND isnull(b.AUTO_INCREMENT,0) =
isnull(ColumnProperty (a.id, a.name, 'IsIdentity'),0) AND (b.ODBCVer is null or b.ODBCVer = 2)
以上在sql 2000中测试通过
这一句更强 (来自网上)
SELECT a.name 字段名,COLUMNPROPERTY(a.id,a.name,'IsIdentity') 标识,
(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) 主键,
b.name 类型,
COLUMNPROPERTY(a.id,a.name,'PRECISION') as 长度,
isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0) as 小数位数,
(case when a.isnullable=1 then '1'else '0' end) 允许空,
isnull(g.[value],'') AS 字段说明
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
where d.name = 'rsk'
order by a.id,a.colorder
相关文章推荐
- 读取sql server表的字段名,字段类型,字段长度,字段属性描述的sql语句
- 读取sql server表的字段名,字段类型,字段长度,字段属性描述的sql语句
- 读取sql server表的字段名,字段类型,字段长度,字段属性的sql语句
- 读取sql server表的字段名,字段类型,字段长度,字段属性的sql语句
- 读取sql server表的字段名,字段类型,字段长度,字段属性描述的sql语句
- (转)列出SQL SERVER 所有表,字段名,主键,类型,长度,小数位数等信息的SQL语句
- SQL Server 2008中获取数据库所有表及其字段名称、类型、长度的SQL
- sql语句取得一个表中的列名,数据类型,及长度等属性
- sql 列出SQL SERVER 所有表,字段名,主键,类型,长度,小数位数等信息
- 用SQL语句查询出所有表的表结构(字段定义,类型,长度等),导出CSV(SQL2008 R2)
- 通过sql语句 获取表的所有字段名 类型等属性
- sql语句查询表的字段类型长度和表说明
- sql server 查询表信息,字段,数据类型的sql语句
- sql server查询所有表名、字段名、类型、长度 和 存储过程、视图 的创建语句
- 用SQL语句获取MSSQL表关键字段的名称、数据类型和长度
- SQL Server 2008中获取数据库所有表及其字段名称、类型、长度的SQL
- SQL Server 查询表的字段对应描述、数据类型、长度
- mysql alter修改字段的长度 类型sql语句
- sql获取表,字段,长度,类型,描述,等详细信息
- MSSQL 如何采用sql语句 获取建表字段说明、字段备注、字段类型、字段长度