SqlServer 查询出列的一些基本信息,表名,列名,数据类型,备注说明,最大宽度,递增,是否为空,是否主键...

SELECT b.name as TableName,a.name ColumnName,c.name as DataType,p.value as Description,a.max_length as MaxLength
,(case a.is_identity when 1 then 'True' else 'False' end) as [Identity]
,(case a.is_nullable when 1 then 'True' else 'False' end) as [IsNull]
,(case k.type when 'PK' then 'True' else 'False' end) as [IsKey]
FROM sys.objects b
INNER JOIN sys.columns a ON a.object_id = b.object_id
LEFT JOIN sys.types c ON a.system_type_id=c.user_type_id
LEFT JOIN sys.extended_properties p ON p.major_id = a.object_id AND p.minor_id = a.column_id and p.name = 'MS_Description'
left join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE scc on scc.TABLE_NAME=b.name and scc.COLUMN_NAME=a.name
left join sys.objects k on k.name=scc.CONSTRAINT_NAME and k.type='PK'
WHERE b.type='U' and a.name='ID'

转载于:https://www.cnblogs.com/shaoming01/archive/2013/03/28/2987225.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值