Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Delete records which has referance to the same able
On 28 Aug 2006 05:52:47 -0700, swadeep.c_at_gmail.com wrote:
>i have a table in which the foreign key referance is to another column
>in the same table.
>
>Now is there any query to delete both the records the child and the
>parent using a single sql query.
>
>the table stucture is as follows
>
>ID, FDB_ID, STD_ID, etc
>
>here FDB_ID id the foreign key for ID
>
>ID FDB_ID ROLL REG_NO ST CD
>38 37 364 929560 491 S
>37 364 929560 491 F
>
>the second record is the parent and the first is the child
>
>Now i need to delete both the records using a single sql query. Can you
>pleas give the query??
DELETE FROM tab WHERE ID IN (37, 38);
Or set ON DELETE CASCADE on the foreign key and delete just the parent.
-- Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis toolReceived on Mon Aug 28 2006 - 08:18:46 CDT