Copy a Table's data from a Stored Procedure
Posted
by Niike2
on Stack Overflow
See other posts from Stack Overflow
or by Niike2
Published on 2010-04-23T08:36:09Z
Indexed on
2010/04/23
8:43 UTC
Read the original article
Hit count: 184
I am learning how to use SQL and Stored Procedures. I know the syntax is incorrect:
Copy data from one table into another table on another Database with a Stored Procedure. The problem is I don't know what table or what database to copy to. I want it to use parameters and not specify the columns specifically.
I have 2 Databases (Master_db and Master_copy) and the same table structure on each DB.
I want to quickly select a table in Master_db and copy that table's data into Master_copy table with same name. I have come up with something like this:
USE Master_DB
CREATE PROCEDURE TransferData
DEFINE @tableFrom, @tableTo, @databaseTo;
INSERT INTO @databaseTo.dbo.@databaseTo
SELECT * FROM Master_DB.dbo.@tableFrom
GO;
© Stack Overflow or respective owner