mysql - Triggers deleted tables -
code says deleted table not exist:
create database trigger_test; use trigger_test; create table students(student_id int(25) primary key not null, first_name varchar(50) not null, last_name varchar(50) not null, contact_number int(35), address varchar(50) not null, zip_code_id int(25) not null, department_id int(25) not null); create table students_backup(student_id int(25) primary key not null, first_name varchar(50) not null, last_name varchar(50) not null, contact_number int(35), address varchar(50) not null, zip_code_id int(25) not null, department_id int(25) not null); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(090322,'mohsin','alvi',5197690,'house 385 street 13 shahzad town',10,0900); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(090329,'hafiz','ata',3969839,'house 15 street 15 johar town',2,0900); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(100258,'abdul','qadeer',5157869,'house 38 street 03 gulshan abad',2,1000); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(100239,'naseem','gulzar',56989745,'house 3 street 33 qasimabad',8,1000); insert students (student_id,first_name,last_name,address,zip_code_id,department_id) values(110369,'faheem','affandi','house 336 street 15 shahzad town',10,1100); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(110879,'qasim','sarfaraz',9635247,'house 69 street 44 junaidabad',9,1100); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(090222,'talha ','salam',5647892,'house 58 street 69 f-8/4',3,0900); insert students (student_id,first_name,last_name,address,zip_code_id,department_id) values(100369,'fahad','ali','house 89 street 06 mohra noor',3,1000); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(110888,'qaleem','khan',5858969,'house 05 street 03 majazi town',5,1100); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(125878,'javaid','azeem',8521473,'house 20 street 20 malik plaza',5,1200); insert students (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values(127777,'mujahid','bilal',5874561,'house 15 street 396 tarlai',6,1200); delimiter $$ create trigger `deleted_backup_trig` after delete on `students` each row begin insert students_backup(student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) select (student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) deleted; end $$
try following. focus on old.
you close.
drop trigger if exists `deleted_backup_trig`; -- added heck of delimiter $$ create trigger `deleted_backup_trig` after delete on `students` each row begin insert students_backup(student_id,first_name,last_name,contact_number,address,zip_code_id,department_id) values (old.student_id,old.first_name,old.last_name,old.contact_number,old.address,old.zip_code_id,old.department_id); end $$
test
delete students student_id=100369; select * students_backup; -- trust me row there
so, there no such thing from deleted
see mysql manual page trigger syntax , examples
Comments
Post a Comment