获取SqlServer2005表结构
1、获取表的基本字段属性
--获取SqlServer中表结构
SELECT syscolumns.name,
systypes.name,
syscolumns.isnullable,
syscolumns.length
FROM syscolumns,
systypes
WHERE syscolumns.xusertype = systypes.xusertype
AND syscolumns.id = Object_id('你的表名')
systypes.name,
syscolumns.isnullable,
syscolumns.length
FROM syscolumns,
systypes
WHERE syscolumns.xusertype = systypes.xusertype
AND syscolumns.id = Object_id('你的表名')
2、获取SqlServer中表结构 主键,及描述
declare@table_nameasvarchar(max)
SET @table_name = '你的表名'
SELECT sys.columns.name,
sys.types.name,
sys.columns.max_length,
sys.columns.is_nullable,
(SELECT Count(* )
FROM sys.identity_columns
WHERE sys.identity_columns.object_id = sys.columns.object_id
AND sys.columns.column_id = sys.identity_columns.column_id) AS is_identity,
(SELECT VALUE
FROM sys.extended_properties
WHERE sys.extended_properties.major_id = sys.columns.object_id
AND sys.extended_properties.minor_id = sys.columns.column_id) AS description
FROM sys.columns,
sys.tables,
sys.types
WHERE sys.columns.object_id = sys.tables.object_id
AND sys.columns.system_type_id = sys.types.system_type_id
AND sys.tables.name = @table_name
ORDER BY sys.columns.column_id
SET @table_name = '你的表名'
SELECT sys.columns.name,
sys.types.name,
sys.columns.max_length,
sys.columns.is_nullable,
(SELECT Count(* )
FROM sys.identity_columns
WHERE sys.identity_columns.object_id = sys.columns.object_id
AND sys.columns.column_id = sys.identity_columns.column_id) AS is_identity,
(SELECT VALUE
FROM sys.extended_properties
WHERE sys.extended_properties.major_id = sys.columns.object_id
AND sys.extended_properties.minor_id = sys.columns.column_id) AS description
FROM sys.columns,
sys.tables,
sys.types
WHERE sys.columns.object_id = sys.tables.object_id
AND sys.columns.system_type_id = sys.types.system_type_id
AND sys.tables.name = @table_name
ORDER BY sys.columns.column_id
3、单独查询表递增字段
select [name] from syscolumns where
id=object_id(N'你的表名') and COLUMNPROPERTY(id,name,'IsIdentity')=1
id=object_id(N'你的表名') and COLUMNPROPERTY(id,name,'IsIdentity')=1