获取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