Home  • Database • MySQL

Suggestion questions on MySQL trigger

MySQL Q1. Why we use triggers? Q2. Write down five limitations of MySQL's trigger. Q3. Create insert,update,delete triggers with appropriate after and before clause on user table Q4. How can you display triggers you have created? Q5. How can you modify trigger? Q6. Write Before triggers vs. After triggers. Q7. Integrate one of your trigger into web application

Comments 13


1. we use triggers for the following purposes:
1. we use triggers for the following purposes: a. to generate immediate audit trails. b. to validate input data before updating database. c. to keep  table relationships stable through the life time of a project.
Q2. Write down five limitations of MySQL's trigger.
Answer:  
•	Temporary tables are not supported
•	Views are not supported
•	Triggers must be unique
•	Error handling and reporting support is immature
Q2. Write down five limitations of MySQL's trigger.
Answer:  
•	Temporary tables are not supported
•	Views are not supported
•	Result sets can’t be returned from a trigger
•	Triggers must be unique
•	Error handling and reporting support is immature
Very good job !!
thank you
Q3. Create insert,update,delete triggers with appropriate after and before clause on user table
[code]
[code]drop if exists log_user;
create table log_user(id int(10) primary key auto_increment,
activity varchar(20), description text, time datetime);

delimiter //
drop trigger if exists au_user//
create trigger au_user after update on user
for each row
begin insert into log_user(activity,description,time) values('UPDATE',concat('Name: ',old.name,'=>',new.name,',Email :',old.email,'=>',new.email),now());
end;//
delimiter ;

delimiter //
drop trigger if exists db_user//
create trigger bd_user before delete on user 
for each row
begin
insert into log_user(activity,description,time)values('DELETE',concat('Name :',old.name,'=>','none',', Email :',old.email,'=>','none'),now());
end;//
delimiter ;

delimiter //
drop trigger if exists ai_user//
create trigger ai_user after insert on user 
for each row
begin
insert into log_user(activity,description,time)values('INSERT',concat('Name :','none','=>',new.name,'Email :','none','=>',new.email),now());
end;//
delimiter ;
[\code]
Q4. How can you display triggers you have created?
mysql> show triggers \G;
Q5. How can you modify trigger?
At the time of writing, there was no supported command or GUI application available for modifying an
existing trigger. Therefore, perhaps the easiest strategy for modifying a trigger is to delete and
subsequently re-create it.
Q6. Write Before triggers vs. After triggers.Before trigger when validating or modifying data that we intend to insert or update. On the other hand, an after trigger should be used when data is to be propagated or verified against other tables, and for carrying out calculations.
show_datetime() function defination

Share

Copyright © 2024. Powered by Intellect Software Ltd