Can we delete rows from multiple tables with a single query (like we are retrieving rows from multiple tables using select statement) ?
for example:
these are my tables
SQL> select * from test12;
ID NAME
--------- ----------
100 srini
200 venu
300 vega
SQL> select * from test13;
ID ADDRESS
--------- ----------
300 add1
200 add2
100 add3
and i have tried to delete as follows
SQL> delete test12,test13 where test12.id=300 and test12.id=test13.id;
delete test12,test13 where test12.id=300 and test12.id=test13.id
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
The on delete cascade option is part of the constraint definition, not the delete command - here is a paste from the Oracle documentation (V7 unfortunately - the only one I have handy at the mo :( ), but it should apply equally to Oracle 8...
-----------------
Maintaining Referential Integrity with the ON DELETE CASCADE Option
If you use the ON DELETE CASCADE option, Oracle7 permits deletions of referenced key values in the parent table and automatically deletes dependent rows in the child table to maintain referential integrity.
Example VII
This example creates the EMP table, defines and enables the referential integrity constraint FK_DEPTNO, and uses the ON DELETE CASCADE option:
CREATE TABLE emp
(empno NUMBER(4),
ename VARCHAR2(10),
job VARCHAR2(9),
mgr NUMBER(4),
hiredate DATE,
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(2) CONSTRAINT fk_deptno
REFERENCES dept(deptno)
ON DELETE CASCADE )
Because of the ON DELETE CASCADE option, Oracle7 cascades any deletion of a DEPTNO value in the DEPT table to the DEPTNO values of its dependent rows of the EMP table. For example, if department 20 is deleted from the DEPT table, Oracle7 deletes the department's employees from the EMP table.
Bookmarks