SELECT a.name, b.rows, 'insert into ' + a.name + '('+c.columns+') select '+c.columns+' from [172.18.65.84].[TEST].[dbo].' + a.name + ';'
FROM sysobjects AS a
INNER JOIN sysindexes AS b ON a.id = b.id
INNER JOIN
(
select id, columns=stuff((select ',['+name +']' from syscolumns where [name] !='OptimisticVersion' and id = col.id for xml path('')),1,1,'') from syscolumns as col
group by id
) c on a.id = c.id
WHERE (a.type = 'u') AND (b.indid IN (0, 1)) and a.name like 'G%' and b.rows>0
ORDER BY b.rows DESC
SQL數據轉插入語句
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.