create PROCEDURE [dbo].[ziduan]
/*
function:查询某个表的字段名,字段类型,长度及字段说明,并asc排序;查询主键信息;查询自增列信息
*/
(
@biaoming nvarchar(50)
)
AS
SET NOCOUNT ON
--获取字段名,长度,缺省值,字段说明sql2000可用
--SELECT [name] = a.name, [type_name] = b.name, length = a.prec,[default]=m.text,[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 left join syscomments m on a.cdefault=m.id where a.id=object_id( @biaoming) order by [name] asc
--sql2005以上可用
SELECT [name] = a.name, [type_name] = b.name, length = a.prec,[default]=m.text,[description] = isnull(g.[value], ' ') FROM syscolumns a left join systypes b on a.xusertype=b.xusertype left join sys.extended_properties g on a.id=g.major_id and a.colid=g.minor_id left join syscomments m on a.cdefault=m.id where a.id=object_id( @biaoming) order by [name] asc
--获取表的主键值
exec sp_pkeys @biaoming
--获取该表自增列的相关信息
Select so.name Table_name, --表名字
sc.name Identity_Column_name, --自增字段名字
ident_current(so.name) curr_value, --自增字段当前值
ident_incr(so.name) incr_value, --自增字段增长值
ident_seed(so.name) seed_value --自增字段种子值
from sysobjects so
Inner Join syscolumns sc
on so.id = sc.id
and columnproperty(sc.id, sc.name, 'IsIdentity') = 1
Where upper(so.name) = upper(@biaoming)
SELECT 索引名称 = a.name ,
表名 = c.name ,
索引字段名 = d.name ,
索引字段位置 = d.colid
FROM sysindexes a
JOIN sysindexkeys b ON a.id = b.id
AND a.indid = b.indid
JOIN sysobjects c ON b.id = c.id
JOIN syscolumns d ON b.id = d.id
AND b.colid = d.colid
WHERE a.indid NOT IN ( 0, 255 )
-- and c.xtype='U' and c.status>0 --查所有用户表
AND c.name = @biaoming --查指定表
ORDER BY c.name ,
a.name ,
d.name
set nocount off
相关文章
- sqlserver查询所有表名、字段名、类型、长度和存储过程、视图的创建语句
- oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息
- 使用sql查询mysql/oracle/sql server/gp数据库中指定表的字段信息(字段名/字段类型/字段长度/是否是主键/是否为空)
- sql server sql查询数据库的表,字段,主键,自增,字段类型等信息
- oracle中查询表的信息,包括表名,字段名,字段类型,主键,外键唯一性约束信息
- sqlserver查询所有表名、字段名、类型、长度和存储过程、视图的创建语句
- 查询某个表的字段名,字段类型,长度及字段说明,查询主键信息,查询自增列信息的存储过程
- 使用sql查询mysql/oracle/sql server/gp数据库中指定表的字段信息(字段名/字段类型/字段长度/是否是主键/是否为空)