This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to delete a parent row when a child is deleted? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to delete a parent row when a child is deleted?" Watch "how to delete a parent row when a child is deleted?" New topic
Author

how to delete a parent row when a child is deleted?

Judy Collins
Greenhorn

Joined: Oct 07, 2004
Posts: 20
Hi guys
This is something similar to cascade deleted that I need.
Cascade delete means that when the parent row is deleted, the children rows are deleted.

How can I delete a parent row when a child is deleted? triggers? functions? any idea?

thanks for your help and have a great weekend
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Think of a trigger & play with it. But dont know whether its a right approach.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Triggers are meant for this.

If you wanna do all in your code then you have to probably go for it by yourself. Although you can do it via code easily, however the opposite case would be complex using code. But in your case

one parent -----> many children

So, you just need to delete one parent. If multiple hierarchies, you need to delete each parent entry. Then even one trigger wouldn't help you straight. You might have to define more than one trigger.
[ March 06, 2005: Message edited by: Adeel Ansari ]
 
jQuery in Action, 2nd edition
 
subject: how to delete a parent row when a child is deleted?
 
Similar Threads
Association problem in delete
hibernate child set didn't deleting the objects when updating
Checking referencial constraint
Deleting from multiple Tables
Hibernate delete exception