CREATE TABLE Employee (

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

POORVA TALEKAR

SE-COMPS-B ROLL NO 49
DBMS EXP NO- 08
→CREATE TABLE Employee(
e_id INT NOT NULL,
e_name VARCHAR(10) NOT NULL,
designation VARCHAR NOT NULL,
salary INT NOT NULL,
dept_no INT NOT NULL,
PRIMARY KEY(e_id)
)
→INSERT INTO Employee
VALUES (1,'Himanshu','Secretary', 30000, 1),
(2,'Rahul','Manager', 40000, 2),
(3,'Prinal','Manager', 35000, 3),
(4,'Dhruvi','HR', 25000, 2),
(5,'Arvind','Manager', 50000, 2),
(6,'Sharan','Clerk', 25000, 1),
(7,'Dhruv','Clerk', 25000, 1),
(8,'Sachin','Manager', 60000, 4),
(9,'Chirag','HR', 30000, 4),
(10,'Rushi','Secretary', 37000, 4)
→Create table Department(Dept_no,Dept_name)& insert
values
• CREATE TABLE Department(
dept_no INT NOT NULL,
dept_name varchar NOT NULL)
INSERT INTO Department
VALUES (1,'Research'),
(2,'Markating'),
(3,'Sales'),
(4,'Engineering')

Dept_no Dept_name
1 Research
2 Marketing
3 Sales
4 Engineering

→Create a view to display details like e_id, e_name and


salary of the Employee.
• CREATE VIEW Details AS
SELECT e_id, e_name, salary
FROM Employee
E_id E_name Salary
1 Himanshu 30000
2 Rahul 40000
3 Primal 35000
4 Dhruvi 25000
5 arvind 50000
6 Sharan 25000
7 dhruv 25000
8 sachin 60000
9 chirag 30000
10 rushi 37000

→Create a view to display the details of only those


employees who are working as
clerk.
• CREATE VIEW D_clerk AS
SELECT *
FROM Employee
WHERE Designation='Clerk'

E_id E_name designation salary Dept_no


6 Sharan Clerk 25000 1
7 dhruv clerk 25000 1

→Create a view to display details like e_id, e_name,


dept_no, dept_name of all
employees.
• CREATE VIEW ed_details AS
SELECT E.e_id, E.e_name, D.dept_no, D.dept_name
FROM Employee AS E, Department AS D
WHERE E.dept_no= D.dept_no

E_id E_name Dept_no Dept_name


7 Dhruv 1 Research
6 Sharan 1 Research
1 Himanshu 1 Research
5 Arvind 2 Marketing
4 Dhruvi 2 marketing
2 Rahul 2 Marketing
3 Prina; 3 Marketing

→Create a view to display details like e_id, e_name,


dept_no, dept_name of all
• employees where designation='Assistant'
CREATE VIEW d_assist AS
SELECT E.e_id, E.e_name, D.dept_no, D.dept_name
FROM Employee AS E, Department AS D
WHERE E.Designation='Clerk' AND E.dept_no= D.dept_no

E_id E_name Dept_no Dept_name


7 Dhruv 1 Research
6 sharan 1 Research

→Delete or update some information from original table


and check whether its
reflected in the any one of the View which you have
created.
• Before Update:

E_ID E_name designation salary Dept_no


6 Sharan Clerk 25000 1
7 dhruv Clerk 25000 1
→After Update
• UPDATE Employee
SET Salary=20000
WHERE Designation='Clerk'

E_ID E_name designation salary Dept_no


6 Sharan Clerk 20000 1
7 dhruv Clerk 20000 1

You might also like