Insert a record in two tables

How to insert a record in two tables with single insert statement ?

Questions by janardanneppali   answers by janardanneppali

Showing Answers 1 - 21 of 21 Answers

If there is any parent-child relation between the table, disable it first.

ALTER TABLE emp
DISABLE CONSTRAINT FK_DEPTNO;

/*Inserting data in two tables in a single query*/
INSERT ALL
INTO dept(DEPTNO, DNAME) VALUES (deptno , dname)
INTO emp (EMPNO, DEPTNO) VALUES (empno , deptno)
SELECT 10 empno , 60 deptno, 'Testing' dname
FROM dual;


ALTER TABLE emp
ENABLE CONSTRAINT FK_DEPTNO;

Nazeera Jaffar

  • Sep 30th, 2012
 

Answer:

Code
  1. INSERT ALL

  2.     INTO first_table VALUES(value1,value2)

  3.      INTO second_table VALUES(value1,value2)

  4.  

  5. SELECT * FROM dual;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions