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

vep temp picture vep temp · Oct 26, 2013 · Viewed 18.3k times · Source

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!

Answer

nvogel picture nvogel · Oct 26, 2013

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