Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Referential Integrity Problem
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00740169
Message ID:
00740187
Views:
29
>Hi Everyone,
>
>In a cascading delete, is there a generally accepted technique to prevent the parent from being deleted if a delete trigger on one of the child records fails. Currently, the parent is deleted regardless of whether all of the child records are deleted or not. This results in orphaned child records in the table (not good.)

Not quite sure what you're asking here. In VFP all RI is handled programmatically, typically by code in stored procedures in the database's .DBC.

VFP automatically generates code here to handle RI requirements. A well regarded replacement is available at http://home.twmi.rr.com/ssawyer/content/ricode.htm

If these don't meet your needs, you can write your own custom RI code either as a stored procedure or procedurally in your application. Pseudocode:
BEGIN TRANSACTION
  DELETE FROM ChildTable WHERE ForeignKey = SomeValue

  SELECT SomeColumn FROM ChildTable WHERE ForeignKey = SomeValue

  IF _TALLY > 0
    * One or more child rows failed to delete:
    ROLLBACK

  ELSE
    END TRANSACTION

    * Delete parent row:
    DELETE FROM ParentTable WHERE PrimaryKey = SomeValue

  ENDIF
You can dress up the above with a transaction around the parent delete, custom ERROR handling, etc.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform