简体   繁体   中英

Microsoft SQL server: copy table from linked server to current database using a stored procedure

I am using Microsoft SQL server. the following code works if run from a QUERY:

SELECT * 
INTO mydatabase.dbo.atable 
FROM linkedserver.sandbox.dbo.atable

but it does not if inserted into a stored procedure:

SET ANSI_NULLS ON  GO 
SET QUOTED_IDENTIFIER ON  GO

ALTER PROCEDURE dataMigration   
AS  BEGIN   
 -- SET NOCOUNT ON added to prevent extra result sets from  
 -- interfering with SELECT statements.     

 SET NOCOUNT ON;

 -- Insert statements for procedure here     
SELECT *     
INTO mydatabase.dbo.atable  
FROM linkedserver.sandbox.dbo.atable   

 END   
GO

Command(s) completes successfully but no table is created into mydatabase. Sorry for the trivial question. I had a look at similar issues but i did not find a case similar to mine.

Thank you for your help.

You have to execute the stored Procedure after you run the code to alter it.

try running:

exec dataMigration

右键单击Option Image存储过程,然后单击“执行存储过程”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM