Tuesday, 23 July 2013

DELETE NO ACTION
Specifies that the row in the parent table can be deleted if no other row depends on it. If a dependent row exists in the relationship, the DELETE fails. The check for dependent rows is performed at the end of the statement.
DELETE RESTRICT
Specifies that the row in the parent table can be deleted if no other row depends on it. If a dependent row exists in the relationship, the DELETE fails. The check for dependent rows is performed immediately.
For example, you cannot delete a department from the department table if it is still responsible for some project that is described by a dependent row in the project table.
DELETE CASCADE
Specifies that first the designated rows in the parent table are deleted. Then, the dependent rows are deleted.
For example, you can delete a department by deleting its row in the department table. Deleting the row from the department table also deletes:
  • The rows for all departments that report to it
  • All departments that report to those departments and so forth.
DELETE SET NULL
Specifies that each nullable column of the foreign key in each dependent row is set to its default value. This means that the column is only set to its default value if it is a member of a foreign key that references the row being deleted. Only the dependent rows that are immediate descendents are affected.
DELETE SET DEFAULT
Specifies that each column of the foreign key in each dependent row is set to its default value. This means that the column is only set to its default value if it is a member of a foreign key that references the row being deleted. Only the dependent rows that are immediate descendants are affected.
For example, you can delete an employee from the employee table (EMPLOYEE) even if the employee manages some department. In that case, the value of MGRNO for each employee who reported to the manager is set to blanks in the department table (DEPARTMENT). If some other default value was specified on the create of the table, that value is used.
This is due to the REPORTS_TO_EXISTS constraint defined for the department table.
If a descendent table has a delete rule of RESTRICT or NO ACTION and a row is found such that a descendant row cannot be deleted, the entire DELETE fails.

No comments:

Post a Comment