This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubts pertaining to deletion of record in Table in Rdbms

 
RabiDas Sharma
Ranch Hand
Posts: 69
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
I'm having Student table which has the attributes like
student_name,id,address etc.
And another Result table that has attributes like
student_id(foreign key references to Student id),test_id(foreign key references test_id in test table) and Mark.

Now my question is, if I delete Student from student table then his result should get deleted i.e, record corresponding to his student_id
in result table should get deleted automatically.
How can I do that??

thanks in advance.
with regards


 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've moved the question to our JDBC forum, where it fits better.

Generally, there are two approaches to this problem:

1) Implement the logic in your application (in Java). You're obviously looking for a different solution, but I think that this one has its advantages too - nothing in your applications gets deleted without you explicitly making it so. Also, in some databases this might perform better than the other option, but it will probably be noticeable for large number of deleted records only.

2) Create a foreign key constrain with the CASCADE DELETE option. Most databases support this construct. If not sure about how to do it, I'd suggest looking up FOREIGN KEY or CASCADE DELETE in your database documentation. This will ensure that the child records will get deleted when the parent table record is deleted.

Also, in most databases it is a good idea to index the foreign key of the child table. It improves the performance of deletes from the parent table.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic