-表的字段名称
select name from syscolumns where id=object_id( '表名 ')
--表的字段数
select count(name) from syscolumns where id=object_id( '表名 ')
最好改成:object_id(N '表名 ')
这样只是规范一些,一般不会出错
select name from syscolumns where id=object_id(N '表名 ')--列名
select name from sysobjects where xtype= 'U '--表名
select name from sysobjects where xtype= 'P '--存储过程
select t1.id tabid,t1.name tabname,t2.name colname,t3.name datatype,t2.lengthfrom sysobjects t1,syscolumns t2,systypes t3
where t1.xtype='U'
and t1.id=t2.id
and t2.xtype=t3.xtype
更详细的说明:
SELECT
表名 = d.name,
表说明 = isnull(f.value, ''),
字段序号 = a.colorder,
字段名 = a.name,
标识 = case when COLUMNPROPERTY(a.id, a.name, 'IsIdentity')= 1 then 'Y'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 'Y' 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 'Y'else '' end,
默认值 = isnull(e.text, ''),
字段说明 = isnull(g.value, '')
FROM syscolumns a
left join systypes b
on a.xusertype = 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 sys.extended_properties g
on a.id = g.major_id and a.colid = g.minor_id
left join sys.extended_properties f
on d.id = f.major_id and f.minor_id = 0
order by d.name,a.colorder
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)