获取SQL数据库的表名,及第一列的注释作为表的说明,生成删除表数据的SQL语句

获取SQL数据库的表名,及第一列的注释作为表的说明,生成删除表数据的SQL语句


select 'delete from ',Name2 ,'--',RANK()OVER  (ORDER BY Name2 DESC) as 序号,字段说明 from 
(
select bb.name as Name2,cc.* from (

select min(minor_id) as minor_id,id from (
SELECT g.minor_id minor_id,a.Name as Name ,a.Length as Len,b.Name as [Type],ISNULL(g.[value], '') AS 字段说明 ,a.id
FROM  syscolumns as a     
left join systypes b on a.xusertype=b.xusertype INNER JOIN dbo.sysobjects d ON a.id = d.id AND d.xtype = 'U'
 AND d.status >= 0 LEFT OUTER JOIN dbo.syscomments e ON a.cdefault = e.id LEFT 
OUTER JOIN sys.extended_properties g ON a.id = g.major_id AND a.colid = g.minor_id AND
 g.name = 'MS_Description' LEFT OUTER JOIN sys.extended_properties f ON d.id = f.major_id AND f.minor_id = 0
 AND f.name = 'MS_Description'where b.Name <> 'sysname' --group by a.id
) gg group by id

)as cc
,
(
SELECT name,id FROM sysobjects where xtype= 'u ') as bb
where bb.id=cc.id
) as dA LEFT JOIN
(
SELECT g.minor_id minor_id,a.Name as Name ,a.Length as Len,b.Name as [Type],ISNULL(g.[value], '') AS 字段说明, a.id as idd,CRDATE
FROM  syscolumns as a     
left join systypes b on a.xusertype=b.xusertype INNER JOIN dbo.sysobjects d ON a.id = d.id AND d.xtype = 'U'
 AND d.status >= 0 LEFT OUTER JOIN dbo.syscomments e ON a.cdefault = e.id LEFT 
OUTER JOIN sys.extended_properties g ON a.id = g.major_id AND a.colid = g.minor_id AND
 g.name = 'MS_Description' LEFT OUTER JOIN sys.extended_properties f ON d.id = f.major_id AND f.minor_id = 0
 AND f.name = 'MS_Description'where b.Name <> 'sysname'

as dB ON dA.minor_id=dB.minor_id and id=idd

 

 

sql

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值