Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the foreign keys automatically get updated as primary table is updated?

Simple Database Design

Above is my simple database design, just wanted to gain information about how things happen as I'm really new at database. Following are my questions:

  1. as I update wall_id in walls table, does the wall_id in wall_categories table also get updated? as the wall_id in wall_categories table references to wall_id in walls table.

  2. same with desktop_id in walls table since it is a foreign key referencing to desktop_id in desktop_wall table, so when I update desktop_id in walls table does the desktop_id in deskotp_wall also gets updated?

  3. if it does not update by default, how can this be done?

Thanks a lot!

like image 830
vep temp Avatar asked Oct 26 '13 17:10

vep temp


1 Answers

This feature is called cascading referential integrity. It's optional when you define a foreign key constraint. The syntax to enable it is described here (Micorosoft SQL but the syntax is standard and most DBMSs support it):

http://technet.microsoft.com/en-us/library/ms186973(v=sql.105).aspx

like image 112
nvogel Avatar answered Oct 30 '22 19:10

nvogel