给大家分享个查看sqlserver数据库中表的详细信息的sql语句(语句来自动软),虽然没有很复杂的技术,但是在sqlserver数据库中能够非常方便的看表的详细结构;结果图如下:
我把它写成了存储过程,调用存储过程时,参数是表名,这样在开发中会给我们一定的帮助
另说明:本方法使用与SQL2000数据库
create proc getTable @tabName varchar(50) =null as SELECT 表名=case a.colorder when 1 then d.name else '' end, 序号=a.colorder, 列名=a.name, 类型=b.name, 长度=CASE WHEN b.name='nchar' THEN a.length/2 WHEN b.name='nvarchar' THEN a.length/2 ELSE a.length END, 精度=COLUMNPROPERTY(a.id,a.name,'PRECISION'), 小数=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0), 标识=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end, 主键=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (SELECT name FROM sysindexes WHERE indid in( SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid ))) then '√' else '' end, 允许空=case when a.isnullable=1 then '√'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' or d.xtype='V') 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=@tabName or @tabName is null order by d.name,a.colorder
相信大家都会使用的吧
另附上支持sql2005和sql2008的地址:http://www.cnblogs.com/ahjesus/archive/2012/12/05/2802738.html