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