我想将数据从一个数据库迁移到另一个数据库。我已经编写了我的sql语句来执行此操作。但是,我面临的问题是,我需要在执行查询之前“使用databasename GO”(我可以同时使用B和A来运行我的脚本吗?)。以下是我的询问。
Use B GO
Use A GO
IF NOT EXISTS (select 1 FROM B.INFORMATION_SCHEMA.TABLES where table_schema = 'dbo' and table_name = 'Animal')
BEGIN
PRINT 'Table does not exist'
RETURN
END
GO
IF NOT EXISTS (select 1 FROM B.INFORMATION_SCHEMA.TABLES where table_schema = 'dbo' and table_name = 'Animal')
BEGIN
PRINT 'Table does not exist'
RETURN
END
GO
SET IDENTITY_INSERT B.[dbo].Animal ON GO
INSERT INTO B.[dbo].Animal
(Id, Name)
SELECT (Id, Name)
From A.dbo.Animal
GO
SET IDENTITY_INSERT B.[dbo].Animal OFF
GO
这会移动数据吗?