Database several tables have primary foreign key relationship how to delete

Source: Internet
Author: User

1. Trigger, database trigger action. When the database is complete,
Delete the main table after the sub-table, connect the database too many times, performance estimation is not good.

2. Cascade Delete

When you create a table, the B table is defined as follows:

CREATE TABLE A (ID varchar ( -) Primary Key,password varchar ( -) notNULL) CREATE TABLE B (IDintIdentity1,1) Primary key,name varchar ( -) notNULL, userId varchar ( -), foreign Key (userId) references a (ID) on DELETE cascade) Table B creates a master code ID for the external code userId corresponding to a, declares the cascading delete test data: Insert a VALUES (' One','AAA') Insert a values (' at','AAA') Insert B values ('da',' One') Insert B values ('das',' One') Insert B values ('ww',' at') Remove the ID in the a table as ' One' Data, found in the B-table UserID as " One"is also automatically deleted by the database, which is the cascade deletion of delete awhereId=' One'

Database several tables have primary foreign key relationship how to delete

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: 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.