sql语句生成sqlserver表架构

select
case when column_id=1 then a.name else '' end 表名,
case when column_id=1 then ISNULL(e.value,'') else '' end 表说明,
b.name 列名,
d.name 类型,
case when b.max_length=-1 then 'MAX' else cast(b.max_length as varchar(20)) end  类型长度,
isnull(c.value,'') 列说明,
case when i.name is not null then '√' else '' end 是否主键,
case when b.is_identity=1 then '√' else '' end 是否自增,
case when b.is_nullable=1 then '√' else '' end 是否可为空
from sys.tables a left join sys.columns b on a.object_id =b.object_id
 left join sys.types d on b.user_type_id=d.user_type_id
 left join sys.extended_properties c on b.object_id=c.major_id and c.minor_id=b.column_id
 left join sys.extended_properties e on b.object_id=e.major_id and e.minor_id=0
 left join (select * from (select * from sys.indexes where is_primary_key=1)g left join SYSINDEXKEYS h on g.object_id=h.id and g.index_id=h.indid)i on i.object_id=b.object_id and i.colid=b.column_id
 order by a.name,b.column_id

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值