PRACADBMS
PRACADBMS
Write a Trigger that stores the old data table of student table in
student_backup while updating thestudent table. Student_backup
(Stud_ID, Stud_name, Address, Contact_no, Branch, Operation_date)
Student (Stud_ID, Stud_name, Address, Contact_no, Branch)
create table student(studId integer primary key,studName varchar(25));
insert into student values(1,'gk');
insert into student values(2,'rs');
select * from student;
Write a trigger which checks the age of employee while inserting the record in emp table. If it is negative then generate the error and display proper
message.
create table employee(empId integer primary key,empName varchar(25),empAge integer);
insert into employee values(1,'gk',25);
select * from employee;
drop trigger checkTrigger;
Delimiter //
create trigger checkTrigger before insert on employee for each row
begin
declare msg varchar(50);
if NEW.empAge <0 then set NEW.empAge = 0;
end if;
end//delimiter ;
insert into employee values(3,'cd',-5);
select * from employee;