Welcome, Guest
Username: Password: Remember me

TOPIC: Foreign Keys Integrity - Please explain?

Foreign Keys Integrity - Please explain? 27 Mar 2012 04:12 #1733

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Hello All,

Could someone please explain to me what the settings in the Foreign Key Integrity are:
  • none
  • reset
  • cascade

That might help me better understand what I am doing when using a FK.

Kind Regards,

Edward
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The administrator has disabled public write access.

Re: Foreign Keys Integrity - Please explain? 28 Mar 2012 04:41 #1750

  • molenwal1
  • molenwal1's Avatar
  • Offline
  • Senior Member
  • Posts: 63
  • Thank you received: 17
  • Karma: 3
Hi Edward,

I think the explanation under the question mark in the builder is already clear:
None : Keep object with his broken key.
Reset : set to 0.
Cascade : delete all objects from this table that refers to it.

An example with two tables:
TableA
TableB: Foreign key TableA_id.

If you delete in TableA a record with TableA_id value 1 the process is:
None:
Records in TableB keeps there reference to TableA_id 1. A result could be that views will not work or at least misses data from TableA because the record does not exist anymore.

Reset:
Records in TableB with TableA_id value 1 will be reset to 0. Same result as above but it is easier to capture the 'wrong' records.

Cascade:
Records in TableB with TableA_id value 1 will be deleted. Dangerous because all records with the TableA_id reference will be deleted in TableB. Important to build in a warning or an extra confirmation of the user.

Hope this will help you.

Best Regards,
Adriaan
Molenwal1 Webdesign
www.molenwal1.nl
The administrator has disabled public write access.
The following user(s) said Thank You: admin, griiettner, VeCrea, edwardcox

Re: Foreign Keys Integrity - Please explain? 28 Mar 2012 04:47 #1751

  • edwardcox
  • edwardcox's Avatar
  • Offline
  • Premium Member
  • Here to help.
  • Posts: 131
  • Thank you received: 26
  • Karma: 12
Big Thanks Adriaan,

Damn that elusive Question Mark help symbol I keep forgetting about.
Your explanation is clear and concise. Much appreciated.

Regards,

Edward
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The administrator has disabled public write access.

Re: Foreign Keys Integrity - Please explain? 30 Mar 2012 07:46 #1789

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
And for the moment, Cook don't ask you anything before to process. It is only an automatism when you are sure of what you do. If not, don't allow final user to delete.
Coding is now a piece of cake
The administrator has disabled public write access.
Time to create page: 0.098 seconds

Get Started