Home >Database >Mysql Tutorial >How to Insert Data from One Table into Another Using a SQL Server Stored Procedure?
SQL Server: Inserting Rows into an Existing Table Using Stored Procedure
In SQL Server, selecting data from one table and inserting it into an existing table using a stored procedure requires a different approach from creating temporary tables. When attempting to use SELECT ... INTO ... to insert data into an existing table, you may encounter an error indicating that the table already exists.
To resolve this issue and insert rows from one table into another, the following steps must be taken:
Here's an example that inserts rows from dbo.TableOne into dbo.TableTwo based on a specified search key:
INSERT INTO dbo.TableTwo (col1, col2) SELECT col1, col2 FROM dbo.TableOne WHERE col3 LIKE @search_key;
By following these steps, you can successfully insert rows from one table into an existing table using a stored procedure in SQL Server.
The above is the detailed content of How to Insert Data from One Table into Another Using a SQL Server Stored Procedure?. For more information, please follow other related articles on the PHP Chinese website!