Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

DBMS 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

St1:

create database db4;

use db4;

create table customer

(ID int primary key,

NAME varchar(20) not null,

AGE int not null,

ADDRESS varchar(20) not null,

SALARY decimal(10,2) not null);

insert into customer(ID,NAME,AGE,ADDRESS,SALARY) values

(1,'Avinash',24,'Mangalore',20000);

insert into customer(ID,NAME,AGE,ADDRESS,SALARY) values

(2,'Bhavish',24,'Mangalore',30000);

insert into customer(ID,NAME,AGE,ADDRESS,SALARY) values

(3,'Chetan',24,'Mangalore',35000);

nsert into customer(ID,NAME,AGE,ADDRESS,SALARY) values

(4,'Krithi',24,'Mangalore',50000);

insert into customer(ID,NAME,AGE,ADDRESS,SALARY) values

(5,'Ramya',24,'Mangalore',40000);

CREATE TRIGGER after_insert_salary_difference

AFTER INSERT ON CUSTOMER

FOR EACH ROW

BEGIN

SET @my_sal_diff =

CONCAT('salary inserted is ', NEW.SALARY);

END;

DELIMITER ;
CREATE TRIGGER after_update_salary_difference

AFTER UPDATE ON CUSTOMER

FOR EACH ROW

BEGIN

DECLARE old_salary DECIMAL(10, 2);

DECLARE new_salary DECIMAL(10, 2);

SET old_salary = OLD.SALARY;

SET new_salary = NEW.SALARY;

SET @my_sal_diff =

CONCAT('salary difference after

update is ', NEW.SALARY - OLD.SALARY);

END;

CREATE TRIGGER after_delete_salary_difference

AFTER DELETE ON CUSTOMER

FOR EACH ROW

BEGIN

SET @my_sal_diff =

CONCAT('salary deleted is ', OLD.SALARY);

END;

INSERT INTO CUSTOMER (ID,NAME, AGE, ADDRESS, SALARY) VALUES

(6,'Shankar', 35, 'Bangalore', 50000.00);

SELECT @my_sal_diff AS SAL_DIFF;

UPDATE CUSTOMER

SET SALARY = 55000.00

WHERE ID = 6;

SELECT @my_sal_diff AS SAL_DIFF;


DELETE FROM CUSTOMER

WHERE ID = 6;

SELECT @my_sal_diff AS SAL_DIFF;

You might also like