Home > database >  The use of MySQL trigger
The use of MySQL trigger

Time:09-21

MySQL to create a trigger, when to register to insert data in the table, with a student number in the data in the table with the student student number, if there is a student number consistent insert which data, or delete the data, trouble bosses to help look at this problem, don't think for three days to

CodePudding user response:

The general idea is as follows:

The create or replace the trigger flip-flop name
After the insert on the table name
For each row
Declare
N number;
The begin
If inserting then
Select count (0) into n from need comparison table name t where t. student id=: new. Student id;
If n=0 then
Related table insert new data operations, such as: insert into the table name (field name... ) values (the corresponding field name... );
The else
Response of delete operations, such as: delete the table name the where condition,
End the if;
end if;
End the trigger name;

  • Related