Home > OS >  how to create stored procedure in mysql with insert into select table statement
how to create stored procedure in mysql with insert into select table statement

Time:11-17

how to create a stored procedure in MySQL with "insert into select table statement"

sample sql query

insert into table2 select * from table 1;

table 1 and table 2 having same structure.

CodePudding user response:

The following SQL statement creates a stored procedure named "CopyTable1" that selects all records from the "table1" and copy into "table2":

CREATE PROCEDURE CopyTable1
AS
Insert into table2 select * from table1
GO;

Execute the stored procedure above as follows:

EXEC CopyTable1;
  • Related