0% found this document useful (0 votes)
5 views4 pages

Dbms End

The document outlines the creation of two SQL tables, Employee and Department, with specified attributes and constraints. It includes SQL queries for performing various types of joins (inner, left outer, right outer, and full outer) between the tables. Additionally, it describes the implementation of row-level triggers for the Employee table to handle insert, update, and delete operations, including converting names to uppercase and displaying salary differences.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Dbms End

The document outlines the creation of two SQL tables, Employee and Department, with specified attributes and constraints. It includes SQL queries for performing various types of joins (inner, left outer, right outer, and full outer) between the tables. Additionally, it describes the implementation of row-level triggers for the Employee table to handle insert, update, and delete operations, including converting names to uppercase and displaying salary differences.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q.

Create two tables named as employee and department with the given constraints
and attributes: Employee table - (Employee Id.(Primary key), Department ID, Name,
Age (check >18), Salary, City) Department table - (Department Id, and Department
name). Apply inner join, left outer join, right outer join and full outer join in the tables
created.
1) Table creation –
create table Employee( employee_idint PTRIMATRY KEY, Department_idint, name
varchar(100),age int, CONSTRAINT age_check CHECK(age>18), salary decimal(10,2), city
varchar(50) );
Create table Department(Department_idint, department_namevarchar (100) );
2) Inner join –
Select Employee.employee_id, Employee.Department_id, Employee.name, Employee.age,
Employee.salary, Employee.city, Department.department_name from Employee INNER
JOIN Department ON Employee.Department_id=Department.Department_id;
3) Left outer Join –
Select Employee.employee_id, Employee.Department_id, Employee.name, Employee.age,
Employee.salary, Employee.city, Department.department_name from Employee LEFT
OUTER JOIN Department ON Employee.Department_id=Department.Department_id;
4) Right outer join –
select Employee.employee_id, Employee.Department_id, Employee.name, Employee.age,
Employee.salary, Employee.city, Department.department_name from Employee RIGHT
OUTER JOIN Department ON Employee.Department_id=Department.Department_id;
5) Full outer join –
Select Employee.employee_id, Employee.Department_id, Employee.name, Employee.age,
Employee.salary, Employee.city, Department.department_name from Employee LEFT
OUTER JOIN Department ON Employee.Department_id=Department.Department_id
UNION
select Employee.employee_id, Employee.Department_id, Employee.name, Employee.age,
Employee.salary, Employee.city, Department.department_name from Employee RIGHT
OUTER JOIN Department ON Employee.Department_id=Department.Department_id;
Q. Create a row level trigger for the customers table that would fire for INSERT or
UPDATE or DELETE operations performed on the EMPLOYEE table. This trigger will
display the salary difference between the old values and new values. Add a new
employee with the salary value inserted and check the result. Try to update the
existing employee salary and see what happens. Delete a record of employees and
check what happens. Convert employee name into uppercase whenever an employee
record is inserted or updated.
1) Insert trigger –
DELIMITER $$
CREATE TRIGGER employee_before_insert BEFORE INSERT ON employees FOR EACH
ROW
BEGIN
IF NEW.name IS NOT NULL THEN
SET NEW.name = UPPER(NEW.name);
END IF;
END$$
DELIMITER ;
2) Update trigger –
DELIMITER $$
CREATE TRIGGER employee_before_update BEFORE UPDATE ON employees FOR EACH
ROW
BEGIN
IF NEW.name IS NOT NULL THEN
SET NEW.name = UPPER(NEW.name);
END IF;
IF OLD.salary IS NOT NULL AND NEW.salary IS NOT NULL THEN
SELECT CONCAT('Salary difference: ', NEW.salary - OLD.salary) AS salary_diff;
END IF;
END$$
DELIMITER ;
3) Delete Trigger –
DELIMITER $$ CREATE TRIGGER employee_before_delete BEFORE DELETE
ON employees FOR EACH ROW
BEGIN
IF OLD.salary IS NOT NULL THEN
SELECT CONCAT('Deleting employee with salary: ', OLD.salary) AS old_salary;
END IF;
END$$
DELIMITER ;

You might also like