• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

doubts pertaining to deletion of record in Table in Rdbms

Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

Posts: 3837
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
Willie Smits increased rainfall 25% in three years by planting trees. Tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic