Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello, How can i insert the data from Table_A into Table_B?
i wanted to stored the ID(table_A) as StudentID(table_B)

What I have tried:

PROCEDURE table_A(
IN prm_ID
)
Begin
 INSERT INTO table_A
              (
              ID,
              name,
              course           
              )
  SELECT      StudentID,
              name,
              stu_course
  FROM        table_B
  WHERE       StudentID= prm_ID
  AND         NOT EXISTS (SELECT 1 FROM table_A WHERE ID= prm_ID);
Posted
Updated 16-Sep-20 21:39pm

1 solution

Your code does quite the opposite: it inserts data from Table_B into Table_A.

What you are looking for is SQL INSERT INTO SELECT Statement[^] which means the syntax is:
SQL
INSERT INTO DestinationTableName (<DestingationColumnList>)
SELECT <SourceColumnList> FROM SourceTableName
WHERE condition;
You have source and destination swapped.
 
Share this answer
 
Comments
BBO001 17-Sep-20 4:52am    
i wanna insert my data from table A to Table B whenever i call the stored procedure
OriginalGriff 17-Sep-20 5:20am    
And your code does it the other way...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900