SQL-cascading Delete and update (referential integrity)

Source: Internet
Author: User

Syntax:
Foreign key
(Column [,... n])
References referenced_table_name [(ref_column [,... n])]
[On Delete cascade]
[On update cascade]

Note:
Column: column name
Referenced_table_name: name of the primary key table referenced by the foreign key
Ref_name: primary key column of the Table to be referenced by the foreign key
On Delete: deletes a cascading.
On update: Update Cascade

 

 

Alter table B add constraint snum

Foreign key (snum) references a (snum) on update cascade, delete cascade;

Alter table c add constraint snum

Foreign key (snum) references a (snum) on Delete cascade, delete cascade;

// Then all records these contain snum = 1 will be deleted from table A, B and C.

Delete from a where snum = 1;

 

// Then all records these contain snum = 2 will be updated from Table A, B and C.

Update a set snum = 11 where snum = 2;

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.