Recent

Author Topic: The discussion about foreign key constraint  (Read 2304 times)

bugxiong

  • Jr. Member
  • **
  • Posts: 63
    • The Lazarus Chinese community
The discussion about foreign key constraint
« on: May 24, 2013, 03:16:17 am »
Today's Reading "SQL anti-patterns", inspired by many.
But one of the foreign key constraint to say, there are a few
Express their views.

Foreign key constraints, mainly used in
1 Make sure the insertion consistency, when inserting a foreign key as the other tables in the table when the checks related to the primary key of the table value exists.
(2) ensure that the update consistency, when the primary key is modified, all foreign key is specified as Patron key table will be updated.

I have a lot of system design is to avoid deletion, update the primary key to avoid in order to avoid the above two problems.

In reality, a record to be deleted, will inevitably lead to operational detail data deleted, even when using a foreign key constraint can not be avoided,

Such as deleting a commodity information, then the corresponding data inside the documents will be cascading deletes (using foreign key associations)

Will result in loss of data. We take a look at why users want to delete a product information,

from :http://www.fpccn.com/thread-2938-1-1.html
The Lazarus Chinese community
http://www.fpccn.com

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: The discussion about foreign key constraint
« Reply #1 on: May 24, 2013, 08:56:01 am »
Unless you disable cascaded deletes in your foreing key constraint of course.... or if you actually need to have that linked information deleted automatically.

Why not throw primary keys out the window while we're at it and let data integrity be managed by application programs?
... Then we can use nice flat files for data storage ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018