同步数据游标

2019-09-02 0 条评论 8 次阅读 0 人点赞

Declare @Name Nvarchar(Max);
Declare @SQL Nvarchar(Max);
Declare @TableName Nvarchar(Max);
Declare @i INT;
Declare @i_2 INT;
DECLARE MKT CURSOR FOR
SELECT Name FROM Sysobjects WHERE xtype = 'U ' AND Name LIKE 'CT_%' ORDER BY name
OPEN MKT
FETCH NEXT FROM MKT INTO @Name
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @Name;
SET @SQL = 'INSERT INTO ' + @Name + ' SELECT * FROM LINK95_XXPT.SEPCO_XXPT.DBO.' + @Name + ' ;'; --查询数据
--SET @SQL = 'SELECT * FROM ' + @Name + ';'; --查询数据
--SET @SQL = 'TRUNCATE TABLE ' + @Name + ';'; --清空数据
--SET @SQL = 'DROP TABLE ' + @Name + ';'; --删除表
--SET @SQL = 'SELECT * INTO ' + @Name + ' FROM LINK95_XXPT.SEPCO_XXPT.DBO.' + @Name + ' ;'; --查询数据

EXEC (@SQL);
FETCH NEXT FROM MKT INTO @Name
END;
CLOSE MKT
DEALLOCATE MKT

GO

root

这个人太懒什么东西都没留下

文章评论(0)