-- Sql Server 数据表同步 库-》新库 DECLARE @tableList TABLE(TableName VARCHAR(100)) INSERT INTO @tableList select name from sysobjects where xtype='U' --SELECT * FROM @tableList DECLARE @ExecuteSql NVARCHAR(4000) DECLARE @TableName NVARCHAR(100)='' WHILE EXISTS (SELECT TOP 1 * FROM @tableList) BEGIN SELECT TOP 1 @TableName = TableName FROM @tableList SET @ExecuteSql = 'INSERT INTO UnileverDB_CN.dbo.' + @TableName + ' SELECT * FROM UnileverDB.dbo.' + @TableName EXEC (@ExecuteSql) DELETE FROM @tableList WHERE TableName = @TableName PRINT '数据表:'+ @TableName + '数据同步完毕' END PRINT '所有表同步完毕!'
标签:同步,ExecuteSql,TableName,tableList,数据表,SELECT From: https://www.cnblogs.com/volts0302/p/18036994