-- tableName表名,sqlName列名,defaultVal就是默认值,字符串表示
SELECT
a.colorder as colOrder,
d.name as tableName,
a.name as sqlName,
convert(int,case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 1 else 0 end) as isIndex,
convert(int,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 1 else 0 end) as isPk,
b.name as sqlTypeName,
a.length as 'length',
convert(int,COLUMNPROPERTY(a.id,a.name,'PRECISION')) as 'size',
convert(int,isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0)) as 'scale',
convert(int,case when a.isnullable=1 then 1 else 0 end) as 'nullable',
convert(varchar(100), isnull(e.text,'')) as defaultVal,
convert(varchar(255), isnull(g.[value],'')) as remarks
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
where 1=1
-- d.name=?
order by
a.id,a.colorder
--显示数据库属性默认值sp_configure
--主键
sp_pkeys '要查的表名'
--所有列的信息,包括类型,默认值等
sp_columns '要查的表名'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)