locked
Best way to delete record from parent table ? RRS feed

  • Question

  • User970350993 posted

    Hi

    If there is parent table which has primary Key and there is a child table which has the Foreign Key. If i have to delete the record from Parent table which has dependence on Child table then what should we have to do ?

    I don't used to delete the record from parent table, if there is dependency.  I generally used to display the alert message "Sorry you cant delete this record".

    Is it the correct approach or wrong ? could you please correct me ?

     

    <mytubeelement data="{"bundle":{"label_delimitor":":","percentage":"%","smart_buffer":"Smart Buffer","start_playing_when_buffered":"Start playing when buffered","sound":"Sound","desktop_notification":"Desktop Notification","continuation_on_next_line":"-","loop":"Loop","only_notify":"Only Notify","estimated_time":"Estimated Time","global_preferences":"Global Preferences","no_notification_supported_on_your_browser":"No notification style supported on your browser version","video_buffered":"Video Buffered","buffered":"Buffered","hyphen":"-","buffered_message":"The video has been buffered as requested and is ready to play.","not_supported":"Not Supported","on":"On","off":"Off","click_to_enable_for_this_site":"Click to enable for this site","desktop_notification_denied":"You have denied permission for desktop notification for this site","notification_status_delimitor":";","error":"Error","adblock_interferance_message":"Adblock (or similar extension) is known to interfere with SmartVideo. Please add this url to adblock whitelist.","calculating":"Calculating","waiting":"Waiting","will_start_buffering_when_initialized":"Will start buffering when initialized","will_start_playing_when_initialized":"Will start playing when initialized","completed":"Completed","buffering_stalled":"Buffering is stalled. Will stop.","stopped":"Stopped","hr":"Hr","min":"Min","sec":"Sec","any_moment":"Any Moment","popup_donate_to":"Donate to","extension_id":null},"prefs":{"desktopNotification":true,"soundNotification":true,"logLevel":0,"enable":true,"loop":false,"hidePopup":false,"autoPlay":false,"autoBuffer":false,"autoPlayOnBuffer":false,"autoPlayOnBufferPercentage":42,"autoPlayOnSmartBuffer":true,"quality":"default","fshd":false,"onlyNotification":false,"enableFullScreen":true,"saveBandwidth":false,"hideAnnotations":false,"turnOffPagedBuffering":false}}" event="preferencesUpdated" id="myTubeRelayElementToPage"></mytubeelement><mytubeelement data="{"loadBundle":true}" event="relayPrefs" id="myTubeRelayElementToTab"></mytubeelement>

    Monday, October 20, 2014 2:08 PM

Answers

  • User-484054684 posted

    Yes, delete cascade is another approach.

    It was recommended in the following article, to use the

    ON DELETE CASCADE

    option if you want rows deleted in the child table when corresponding rows are deleted in the parent table. If you do not specify cascading deletes, the default behavior of the database server prevents you from deleting data in a table if other tables reference it.

    Reference: http://www.codeproject.com/Articles/620086/CASCADE-in-SQL-Server-with-example

    For oracle: http://www.techonthenet.com/oracle/foreign_keys/foreign_delete.php

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2014 2:11 PM
  • User71929859 posted

    Thanks for sending reply. But in this approach without warning message it will delete all record from child table. we can give alert message before deleting record.

    Generally which one is more acceptable approach ?

    It depends on your project really. There is no acceptable approach. We use both approaches depending on the situation. If we need to delete the whole set of data associated when we delete a particular record, then we use ON CASCADE DELETE.

    As for the alert message, when you click on the delete button you can simply have a javascript confirm asking whether user really needs to delete the record. On that message, also mention that all the associated data will be deleted as well so the user is aware about what's happening.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 21, 2014 1:27 AM

All replies

  • User-484054684 posted

    Yes, delete cascade is another approach.

    It was recommended in the following article, to use the

    ON DELETE CASCADE

    option if you want rows deleted in the child table when corresponding rows are deleted in the parent table. If you do not specify cascading deletes, the default behavior of the database server prevents you from deleting data in a table if other tables reference it.

    Reference: http://www.codeproject.com/Articles/620086/CASCADE-in-SQL-Server-with-example

    For oracle: http://www.techonthenet.com/oracle/foreign_keys/foreign_delete.php

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 20, 2014 2:11 PM
  • User970350993 posted

    Thanks for sending reply. But in this approach without warning message it will delete all record from child table. we can give alert message before deleting record.

    Generally which one is more acceptable approach ?

    <mytubeelement data="{"bundle":{"label_delimitor":":","percentage":"%","smart_buffer":"Smart Buffer","start_playing_when_buffered":"Start playing when buffered","sound":"Sound","desktop_notification":"Desktop Notification","continuation_on_next_line":"-","loop":"Loop","only_notify":"Only Notify","estimated_time":"Estimated Time","global_preferences":"Global Preferences","no_notification_supported_on_your_browser":"No notification style supported on your browser version","video_buffered":"Video Buffered","buffered":"Buffered","hyphen":"-","buffered_message":"The video has been buffered as requested and is ready to play.","not_supported":"Not Supported","on":"On","off":"Off","click_to_enable_for_this_site":"Click to enable for this site","desktop_notification_denied":"You have denied permission for desktop notification for this site","notification_status_delimitor":";","error":"Error","adblock_interferance_message":"Adblock (or similar extension) is known to interfere with SmartVideo. Please add this url to adblock whitelist.","calculating":"Calculating","waiting":"Waiting","will_start_buffering_when_initialized":"Will start buffering when initialized","will_start_playing_when_initialized":"Will start playing when initialized","completed":"Completed","buffering_stalled":"Buffering is stalled. Will stop.","stopped":"Stopped","hr":"Hr","min":"Min","sec":"Sec","any_moment":"Any Moment","popup_donate_to":"Donate to","extension_id":null},"prefs":{"desktopNotification":true,"soundNotification":true,"logLevel":0,"enable":true,"loop":false,"hidePopup":false,"autoPlay":false,"autoBuffer":false,"autoPlayOnBuffer":false,"autoPlayOnBufferPercentage":42,"autoPlayOnSmartBuffer":true,"quality":"default","fshd":false,"onlyNotification":false,"enableFullScreen":true,"saveBandwidth":false,"hideAnnotations":false,"turnOffPagedBuffering":false}}" event="preferencesUpdated" id="myTubeRelayElementToPage"></mytubeelement><mytubeelement data="{"loadBundle":true}" event="relayPrefs" id="myTubeRelayElementToTab"></mytubeelement>

    Monday, October 20, 2014 10:49 PM
  • User71929859 posted

    Thanks for sending reply. But in this approach without warning message it will delete all record from child table. we can give alert message before deleting record.

    Generally which one is more acceptable approach ?

    It depends on your project really. There is no acceptable approach. We use both approaches depending on the situation. If we need to delete the whole set of data associated when we delete a particular record, then we use ON CASCADE DELETE.

    As for the alert message, when you click on the delete button you can simply have a javascript confirm asking whether user really needs to delete the record. On that message, also mention that all the associated data will be deleted as well so the user is aware about what's happening.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 21, 2014 1:27 AM