Comp.dbms File
Comp.dbms File
5th Semester
Subject: - Computer Laboratory and Practical Work of DBMS
Code: - BCA-507P
This is to certify that Mr. Rajnish Mishra of BCA 5th semester has
completed his file on “Computer Laboratory and Practical Work of
DBMS ”on his own. His work is up to my satisfaction.
Create a table EMPLOYEE with following schema: (Emp_no, E_name, E_address, E_ph_no,
Dept_no, Dept_name,Job_id, Designation , Salary)
1. List the E_no, E_name, Salary of all employees working for MANAGER.
2. Display all the details of the employee whose salary is more than the Sal of any IT PROFF..
3. List the employees in the ascending order of Designations of those joined after 1981.
4. List the employees along with their Experience and Daily Salary.
5. List the employees who are either ‘CLERK’ or ‘ANALYST’ .
6. List the employees who joined on 1-MAY-81, 3-DEC-81, 17-DEC-81,19-JAN-80 .7. List the
employees who are working for the Deptno 10 or20.
8. List the Enames those are starting with ‘S’ .
9. Dislay the name as well as the first five characters of name(s) starting with ‘H’
10. List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.
1. Display all the dept numbers available with the dept and emp tables avoiding duplicates.
2. Display all the dept numbers available with the dept and emp tables.
3. Display all the dept numbers available in emp and not in dept tables and vice versa.
1. Find all information of sailors who have reserved boat number 101.
2. Find the name of boat reserved by Bob.
3. Find the names of sailors who have reserved a red boat, and list in the order of age.
INDEX
4. Find the names of sailors who have reserved at least one boat.
5. Find the ids and names of sailors who have reserved two different boats on the same day.
6. Find the ids of sailors who have reserved a red boat or a green boat.
7. Find the name and the age of the youngest sailor.
8. Count the number of different sailor names.
9. Find the average age of sailors for each rating level.
10. Find the average age of sailors for each rating level that has at least two sailors.
6. Experiment No. 6 24-28
1. Find all information of sailors who have reserved boat number 101.
2. Find the name of boat reserved by Bob.
3. Find the names of sailors who have reserved a red boat, and list in the order of age.
4. Find the names of sailors who have reserved at least one boat.
5. Find the ids and names of sailors who have reserved two different boats on the same day.
6. Find the ids of sailors who have reserved a red boat or a green boat.
7. Find the name and the age of the youngest sailor.
8. Count the number of different sailor names.
9. Find the average age of sailors for each rating level.
10. Find the average age of sailors for each rating level that has at least two sailors.
1. Create user and implement the following commands on relation (Emp and Dept).
2. Develop a query to grant all privileges of employees table into departments table.
3. Develop a query to grant some privileges of employees table into departments table.
4. Develop a query to revoke all privileges of employees table from departments table.
5. Develop a query to revoke some privileges of employees table from departments table.
Experiment No. 1
Code: -
1. Create the EMPLOYEE Table
CREATE TABLE EMPLOYEE (
Emp_no INT,
E_name VARCHAR(50),
E_address VARCHAR(100),
E_ph_no VARCHAR(15),
Dept_no INT,
Dept_name VARCHAR(50),
Job_id CHAR(10),
Salary DECIMAL(10, 2)
);
Output:
Field Type Null Key Default Extra
1
2. Add a New Column HIREDATE
ALTER TABLE EMPLOYEE
ADD HIREDATE DATE;
Output:
Field Type Null Key Default Extra
E_no INT NO PRI NULL
E_name VARCHAR(50) YES NULL
E_address VARCHAR(100) YES NULL
E_ph_no VARCHAR(15) YES NULL
Dept_no INT YES NULL
Dept_name VARCHAR(50) YES NULL
Job_id VARCHAR2(20) YES NULL
Salary DECIMAL(10, 2) YES NULL
HIREDATE DATE YES NULL
Output:
Field Type Null Key Default Extra
Job_id VARCHAR2(20) YES NULL
2
4. Change the Name of Emp_no to E_no
ALTER TABLE EMPLOYEE
RENAME COLUMN Emp_no TO E_no;
Output:
Field Type Null Key Default Extra
Output:
Field Type Null Key Default Extra
3
Experiment No. 2
Create a table EMPLOYEE with following schema:
(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name,Job_id , Salary)
1. Insert aleast 5 rows in the table.
2. Display all the information of EMP table.
3. Display the record of each employee who works in department D10.
4. Update the city of Emp_no-12 with current city as Nagpur.
5. Display the details of Employee who works in department MECH.
6. Delete the email_id of employee James.
7. Display the complete record of employees working in SALES Department.
Code: -
1. Create the EMPLOYEE Table
CREATE TABLE EMPLOYEE (
Emp_no INT,
E_name VARCHAR(50),
E_address VARCHAR(100),
E_ph_no VARCHAR(15),
Dept_no INT,
Dept_name VARCHAR(50),
Job_id CHAR(10),
Salary DECIMAL(10, 2)
);
Output:-
Field Type Null Key Default Extra
4
Job_id VARCHAR2(20) YES NULL
Salary DECIMAL(10, 2) YES NULL
Output:
Query ok, 5 rows affected.
Output: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Salary HIREDATE
5
4. Display the Record of Each Employee Who Works in Department D10:
SELECT * FROM EMPLOYEE WHERE Dept_no = 'D10';
Output: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Salary HIREDATE
Output: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Salary HIREDATE
6
7. Delete the email_id of employee James.
UPDATE EMPLOYEE
SET E_ph_no = NULL
WHERE E_name = 'James';
Output:
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Salary HIREDATE
Output:
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Salary HIREDATE
7
Experiment No. 3
Create a table EMPLOYEE with following schema: (Emp_no, E_name, E_address, E_ph_no,
Dept_no, Dept_name,Job_id, Designation , Salary)
1. List the E_no, E_name, Salary of all employees working for MANAGER.
2. Display all the details of the employee whose salary is more than the Sal of any IT PROFF..
3. List the employees in the ascending order of Designations of those joined after 1981.
4. List the employees along with their Experience and Daily Salary.
5. List the employees who are either ‘CLERK’ or ‘ANALYST’ .
6. List the employees who joined on 1-MAY-81, 3-DEC-81, 17-DEC-81,19-JAN-80 .7. List the
employees who are working for the Deptno 10 or20.
8. List the Enames those are starting with ‘S’ .
9. Dislay the name as well as the first five characters of name(s) starting with ‘H’
10. List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.
Code:-
1. Create the EMPLOYEE table
CREATE TABLE EMPLOYEE (
Emp_no INT PRIMARY KEY,
E_name VARCHAR(100),
E_address VARCHAR(255),
E_ph_no VARCHAR(20),
Dept_no INT,
Dept_name VARCHAR(50),
Job_id INT,
Designation VARCHAR(50),
Salary DECIMAL(10, 2)
);
8
Output: -
DESCRIBE EMPLOYEE;
1. List the E_no, E_name, Salary of all employees working for MANAGER.
CODE: -
SELECT Emp_no, E_name, Salary
FROM EMPLOYEE
WHERE Designation = 'MANAGER';
OUTPUT: -
Emp_no E_name Salary
9
2. Display all the details of the employee whose salary is more than the Sal of any IT PROFF.
CODE: -
SELECT * FROM EMPLOYEE
WHERE Salary > (SELECT Salary FROM EMPLOYEE WHERE Designation = 'IT PROFF');
OUTPUT: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Designation Salary
1003 Akash Address A 123456 1 IT 101 MANAGER 6000
1004 Kavya Address B 789012 2 Finance 102 ANALYST 6200
3. List the employees in the ascending order of Designations of those joined after 1981.
CODE: -
SELECT *
FROM EMPLOYEE
WHERE Date_of_joining > '1981-01-01'
ORDER BY Designation ASC;
OUPUT: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Designation Salary Date_of_joining
4. List the employees along with their Experience and Daily Salary.
CODE: -
SELECT E_name,
TIMESTAMPDIFF(YEAR, Date_of_joining, CURDATE()) AS Experience,
Salary / 30 AS Daily_Salary
FROM EMPLOYEE;
10
OUTPUT: -
E_name Experience Daily_Salary
Rajesh 20 166.67
Priya 19 183.33
OUTPUT: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Designation Salary
1005 Rohit Address C 345678 1 IT 103 CLERK 3000
1004 Kavya Address B 789012 2 Finance 102 ANALYST 6200
OUTPUT: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Designation Salary Date_of_joining
1007 Neha Address E 567890 1 IT 105 MANAGER 7000 1981-05-01
1008 Arjun Address F 112233 2 Finance 106 CLERK 3200 1981-12-03
11
7. List the employees who are working for the Deptno 10 or20.
CODE: -
SELECT *
FROM EMPLOYEE
WHERE Dept_no IN (10, 20);
OUTPUT: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Designation Salary
1009 Laxmi Address G 445566 10 Sales 107 ANALYST 4500
1010 Ramesh Address H 778899 20 Marketing 108 CLERK 2800
OUTPUT: -
E_name
Suraj
Shruti
9. Dislay the name as well as the first five characters of name(s) starting with ‘H’
CODE: -
SELECT E_name, SUBSTRING(E_name, 1, 5) AS First_Five_Chars
FROM EMPLOYEE
WHERE E_name LIKE 'H%';
OUTPUT: -
E_name First_Five_Chars
Harsha Harsh
Hema Hema
12
10. List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.
CODE: -
SELECT *
FROM EMPLOYEE
WHERE Designation NOT IN ('PRESIDENT', 'MGR')
ORDER BY Salary ASC;
OUTPUT: -
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Designation Salary
13
Experiment No. 4
1. Display all the dept numbers available with the dept and emp tables avoiding duplicates.
2. Display all the dept numbers available with the dept and emp tables.
3. Display all the dept numbers available in emp and not in dept tables and vice versa.
CREATE EMP TABLE:
Emp_no E_name E_address E_ph_no Dept_no Dept_name Job_id Salary HIREDATE Dept
3 Arjun 789 Lajpat 9811223344 FN02 Finance ACC 4500.00 2023-03- Department
Nagar 20 C
4 James 101 Park 9812341234 SL03 Sales SLM 5200.00 2023-04- Department
Street 12 D
5 Anjali 202 King 9898123456 ME04 MECH ENG 6000.00 2023-05- Department
Circle 05 E
1. Display all the dept numbers available with the dept and emp tables avoiding duplicates:
Code: -
Output: -
Dept_no
D10
IT01
FN02
SL03
ME04
CS05
AE06
14
2. Display all the dept numbers available with the dept and emp tables:
Code: -
SELECT Dept_no
FROM emp
UNION ALL
SELECT Dept_no
FROM dept;
Output: -
Dept_no
D10
IT01
FN02
SL03
ME04
CS05
D10
IT01
FN02
SL03
ME04
AE06
3. Display all the dept numbers available in emp and not in dept tables and vice versa:
Code: -
SELECT Dept_no
FROM emp
WHERE Dept_no NOT IN (SELECT Dept_no FROM dept);
15
Output: -
Dept_no
CS05
16
Experiment No. 5
Consider the following schema:
Sailors (sid, sname, rating, age)
Boats (bid, bname, color)
Reserves (sid, bid, day(date))
1. Find all information of sailors who have reserved boat number 101.
2. Find the name of boat reserved by Bob.
3. Find the names of sailors who have reserved a red boat, and list in the order of age.
4. Find the names of sailors who have reserved at least one boat.
5. Find the ids and names of sailors who have reserved two different boats on the same day.
6. Find the ids of sailors who have reserved a red boat or a green boat.
7. Find the name and the age of the youngest sailor.
8. Count the number of different sailor names.
9. Find the average age of sailors for each rating level.
10. Find the average age of sailors for each rating level that has at least two sailors.
Sailors Table:
sid sname rating age
1 Raj 7 34
2 Priya 8 28
3 Arjun 9 42
4 James 6 36
5 Anjali 7 30
6 Kabir 8 27
7 Neha 9 32
8 Amit 6 40
9 Bob 7 35
17
Boats Table:
bid bname color
Reserves Table:
sid bid day
1 101 2025-01-10
2 102 2025-02-15
3 103 2025-03-20
4 101 2025-04-12
5 104 2025-05-05
1 103 2025-06-10
2 105 2025-07-15
3 101 2025-08-20
6 106 2025-09-25
7 104 2025-10-30
8 101 2025-11-12
9 102 2025-12-01
18
1. Find all information of sailors who have reserved boat number 101:
Code: -
SELECT s.*
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
WHERE r.bid = 101;
Output:
sid sname rating age
1 Raj 7 34
4 James 6 36
3 Arjun 9 42
8 Amit 6 40
Output:
bname
SeaBreeze
19
3. Find the names of sailors who have reserved a red boat, and list in the order of age:
Code: -
SELECT DISTINCT s.sname
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
JOIN Boats b ON r.bid = b.bid
WHERE b.color = 'red'
ORDER BY s.age;
Output:
sname
Raj
James
Amit
5. Find the names of sailors who have reserved at least one boat:
Code: -
SELECT DISTINCT s.sname
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid;
Output: -
sname
Raj
Priya
Arjun
James
Anjali
Kabir
Neha
Amit
20
5. Find the ids and names of sailors who have reserved two different boats on the same day:
Code: -
SELECT s.sid, s.sname
Sailors s
JOIN Reserves r1 ON s.sid = r1.sid
JOIN Reserves r2 ON s.sid = r2.sid
WHERE r1.day = r2.day AND r1.bid <> r2.bid;
Output: -
sid sname
1 Raj
4 James
6. Find the ids of sailors who have reserved a red boat or a green boat:
Code:-
SELECT DISTINCT s.sid
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
JOIN Boats b ON r.bid = b.bid
WHERE b.color = 'red' OR b.color = 'green';
Output:
sid
1
3
4
5
6
21
7. Find the name and the age of the youngest sailor:
Code:-
SELECT s.sname, s.age
FROM Sailors s
ORDER BY s.age ASC
LIMIT 1;
Output: -
sname age
Kabir 27
22
10. Find the average age of sailors for each rating level that has at least two sailors:
Code:-
SELECT s.rating, AVG(s.age) AS avg_age
FROM Sailors s
GROUP BY s.rating
HAVING COUNT(s.sid) >= 2;
Output:
rating avg_age
6 38.00
7 32.00
8 27.50
9 37.00
23
Experiment No. 6
Code: -
SELECT JobCategory, SUM(Salary) AS TotalSalary
FROM Employee
GROUP BY JobCategory;
Output:
JobCategory TotalSalary
Developer 74000
Analyst 31000
Manager 41000
24
2. Display lowest paid employee details under each manager:
Code: -
SELECT EmpName, ManagerID, Salary
FROM Employee e1
WHERE Salary = (SELECT MIN(Salary)
FROM Employee e2
WHERE e2.ManagerID = e1.ManagerID);
Output:
3. Display number of employees working in each department and their department name:
Code: -
SELECT DeptName, COUNT(*) AS EmployeeCount
FROM Employee
GROUP BY DeptName;
Output: -
DeptName EmployeeCount
IT 3
Finance 3
Marketing 2
HR 1
Code: -
SELECT *
FROM Employee
ORDER BY Salary ASC;
25
Output:-
5. Show the record of employee earning salary greater than 16000 in each department:
Code: -
SELECT *
FROM Employee
WHERE Salary > 16000
ORDER BY DeptName, Salary;
Output:
EmpID EmpName JobCategory ManagerID DeptID DeptName Salary
1 Raj Developer 3 101 IT 18000
3 Arjun Manager NULL 101 IT 20000
4 James Developer 3 101 IT 17000
7 Neha Analyst 5 102 Finance 16000
2 Priya Analyst 3 102 Finance 15000
5 Anjali Manager NULL 102 Finance 21000
GROUP BY Clause
Code: -
SELECT JobCategory, SUM(Salary) AS TotalSalary
FROM Employee
GROUP BY JobCategory;
26
Output:
JobCategory TotalSalary
Developer 74000
Analyst 31000
Manager 41000
HAVING Clause
Code: -
SELECT JobCategory, SUM(Salary) AS TotalSalary
FROM Employee
GROUP BY JobCategory
HAVING SUM(Salary) > 30000;
Output:
JobCategory TotalSalary
Developer 74000
Manager 41000
ORDER BY Clause
Code: -
SELECT *
FROM Employee
ORDER BY Salary ASC;
Output:
EmpID EmpName JobCategory ManagerID DeptID DeptName Salary
9 Bob Developer 3 104 HR 12000
8 Amit Developer 5 103 Marketing 13000
6 Kabir Developer 5 103 Marketing 14000
2 Priya Analyst 3 102 Finance 15000
7 Neha Analyst 5 102 Finance 16000
4 James Developer 3 101 IT 17000
1 Raj Developer 3 101 IT 18000
3 Arjun Manager NULL 101 IT 20000
5 Anjali Manager NULL 102 Finance 21000
27
JOIN Clause
Code: -
SELECT e1.EmpName AS Employee, e2.EmpName AS Manager
FROM Employee e1
LEFT JOIN Employee e2 ON e1.ManagerID = e2.EmpID;
Output:
Employee Manager
Raj Arjun
Priya Arjun
Arjun NULL
James Arjun
Anjali NULL
Kabir Anjali
Neha Anjali
Amit Anjali
Bob Arjun
28
Experiment No. 7
Consider the following schema:
Sailors (sid, sname, rating, age)
Boats (bid, bname, color)
Reserves (sid, bid, day(date))
1. Find all information of sailors who have reserved boat number 101.
2. Find the name of boat reserved by Bob.
3. Find the names of sailors who have reserved a red boat, and list in the order of age.
4. Find the names of sailors who have reserved at least one boat.
5. Find the ids and names of sailors who have reserved two different boats on the same day.
6. Find the ids of sailors who have reserved a red boat or a green boat.
7. Find the name and the age of the youngest sailor.
8. Count the number of different sailor names.
9. Find the average age of sailors for each rating level.
10. Find the average age of sailors for each rating level that has at least two sailors.
Sailors Table:
sid sname rating age
1 Raj 7 34
2 Priya 8 28
3 Arjun 9 42
4 James 6 36
5 Anjali 7 30
6 Kabir 8 27
7 Neha 9 32
8 Amit 6 40
9 Bob 7 35
29
Boats Table:
bid bname color
Reserves Table:
sid bid day
1 101 2025-01-10
2 102 2025-02-15
3 103 2025-03-20
4 101 2025-04-12
5 104 2025-05-05
1 103 2025-06-10
2 105 2025-07-15
3 101 2025-08-20
6 106 2025-09-25
7 104 2025-10-30
8 101 2025-11-12
9 102 2025-12-01
30
2. Find all information of sailors who have reserved boat number 101:
Code: -
SELECT s.*
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
WHERE r.bid = 101;
Output:
sid sname rating age
1 Raj 7 34
4 James 6 36
3 Arjun 9 42
8 Amit 6 40
Output:
bname
SeaBreeze
3. Find the names of sailors who have reserved a red boat, and list in the order of age:
Code: -
SELECT DISTINCT s.sname
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
31
JOIN Boats b ON r.bid = b.bid
WHERE b.color = 'red'
ORDER BY s.age;
Output:
sname
Raj
James
Amit
5. Find the names of sailors who have reserved at least one boat:
Code: -
SELECT DISTINCT s.sname
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid;
Output: -
sname
Raj
Priya
Arjun
James
Anjali
Kabir
Neha
Amit
32
5. Find the ids and names of sailors who have reserved two different boats on the same day:
Code: -
SELECT s.sid, s.sname
Sailors s
JOIN Reserves r1 ON s.sid = r1.sid
JOIN Reserves r2 ON s.sid = r2.sid
WHERE r1.day = r2.day AND r1.bid <> r2.bid;
Output: -
sid sname
1 Raj
4 James
6. Find the ids of sailors who have reserved a red boat or a green boat:
Code:-
SELECT DISTINCT s.sid
FROM Sailors s
JOIN Reserves r ON s.sid = r.sid
JOIN Boats b ON r.bid = b.bid
WHERE b.color = 'red' OR b.color = 'green';
Output:
sid
1
3
4
5
6
33
7. Find the name and the age of the youngest sailor:
Code:-
SELECT s.sname, s.age
FROM Sailors s
ORDER BY s.age ASC
LIMIT 1;
Output: -
sname age
Kabir 27
34
10. Find the average age of sailors for each rating level that has at least two sailors:
Code:-
SELECT s.rating, AVG(s.age) AS avg_age
FROM Sailors s
GROUP BY s.rating
HAVING COUNT(s.sid) >= 2;
Output:
rating avg_age
6 38.00
7 32.00
8 27.50
9 37.00
35
Experiment No. 8
1. Create a table called EMP with the following structure.
Name Type
EMPNO NUMBER (6)
ENAME VARCHAR2 (20)
JOB VARCHAR2 (10)
DEPTNO NUMBER (3)
SAL NUMBER (7,2)
Allow NULL for all columns except ename and job.
2. Add constraints to check, while entering the empno value (i.e) empno > 100.
3. Define the field DEPTNO as unique.
4. Create a primary key constraint for the table(EMPNO).
5. Write queries to implement and practice constraints.
2. Add constraints to check, while entering the empno value (i.e., empno > 100):
Code: -
CONSTRAINT CHK_EMPNO CHECK (EMPNO > 100)
36
3. Define the field DEPTNO as unique:
Code: -
CONSTRAINT UNQ_DEPTNO UNIQUE (DEPTNO)
37
Attempt to Insert Invalid Data:
Attempt to insert empno less than 100 (should fail):
Code:-
INSERT INTO EMP (EMPNO, ENAME, JOB, DEPTNO, SAL)
VALUES (99, 'Tom', 'Clerk', 60, 2000.00);
Output: -
Error Message: ORA-02290: check constraint (CHK_EMPNO) violated
38
Errors:
Attempt Error Message
Insert empno < 100 ORA-02290: check constraint (CHK_EMPNO) violated
Insert duplicate DEPTNO ORA-00001: unique constraint (UNQ_DEPTNO)
violated
Insert record with missing ENAME or ORA-01400: cannot insert NULL into ("ENAME" or
JOB "JOB")
39
Experiment No. 9
Create Dataset
Code: -
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
salary DECIMAL(10, 2)
);
INSERT INTO employees (employee_id, first_name, last_name, salary) VALUES
(1, 'John', 'Doe', 50000),
(2, 'Jane', 'Smith', 60000),
(3, 'Michael', 'Brown', 70000);
40
2. Query to implement the rollback:
Code:-
INSERT INTO employees (employee_id, first_name, last_name, salary) VALUES (4, 'Alice', 'Johnson',
80000);
SAVEPOINT savepoint2;
INSERT INTO employees (employee_id, first_name, last_name, salary) VALUES (5, 'Bob', 'Williams',
55000);
ROLLBACK TO SAVEPOINT savepoint2;
Output: - The insertion of the employee with employee_id = 5 is undone. The table will only have
the new employee Alice added.
employee_id first_name last_name salary
41
3. Write a Query to implement the commit:
Code: -
INSERT INTO employees (employee_id, first_name, last_name, salary) VALUES
(6, 'Charlie', 'Davis', 45000);
COMMIT;
Output: The insertion of the employee with employee_id = 6 is made permanent in the database.
employee_id first_name last_name salary
42
Experiment No. 10
1. Create user and implement the following commands on relation (Emp and Dept).
2. Develop a query to grant all privileges of employees table into departments table.
3. Develop a query to grant some privileges of employees table into departments table.
4. Develop a query to revoke all privileges of employees table from departments table.
5. Develop a query to revoke some privileges of employees table from departments table.
1. Create user and implement the following commands on relation (Emp and Dept).
Code: -
CREATE USER employee_user IDENTIFIED BY password111;
GRANT CONNECT, RESOURCE TO employee_user;
Grant the necessary privileges to the user
GRANT SELECT, INSERT, UPDATE, DELETE ON Emp TO employee_user;
GRANT SELECT, INSERT, UPDATE, DELETE ON Dept TO employee_user;
DESCRIBE user creation and privileges granted to employee_user on Emp and Dept tables;
Output:
User 'employee_user created successfully.
'CONNECT' and 'RESOURCE' roles granted to 'employee_user'.
'SELECT', 'INSERT', 'UPDATE', and 'DELETE' privileges granted on 'Emp' and 'Dept' tables to
'employee_user'.
2. Develop a query to grant all privileges of employees table into departments table.
Code:-
GRANT ALL PRIVILEGES ON Emp TO Dept;
DESCRIBE granting all privileges from Emp to Dept table;
Output: -
All privileges granted from 'Emp' to 'Dept'. This allows the 'Dept' table full access (SELECT, INSERT,
UPDATE, DELETE) on the 'Emp' table.
3. Develop a query to grant some privileges of employees table into departments table.
Code:-
GRANT SELECT, INSERT ON Emp TO Dept;
DESCRIBE granting specific privileges (SELECT, INSERT) from Emp to Dept table;
Output: -
SELECT and 'INSERT' privileges granted from 'Emp' to 'Dept table. Now the 'Dept' table can only
query and insert data into the Emp' table.
43
4. Develop a query to revoke all privileges of employees table from departments table.
Code:-
REVOKE ALL PRIVILEGES ON Emp FROM Dept;
DESCRIBE revoking all privileges from Dept on Emp table;
Output: -
All privileges (SELECT, INSERT, UPDATE, DELETE) have been revoked from 'Dept' on the 'Emp table.
The 'Dept' table can no longer access or modify data in 'Emp'.
5. Develop a query to revoke some privileges of employees table from departments table.
Code:-
REVOKE SELECT, INSERT ON Emp FROM Dept;
DESCRIBE revoking specific privileges (SELECT, INSERT) from Dept on Emp table;
Output: -
SELECT' and 'INSERT privileges have been revoked from 'Dept' on the 'Emp' table. The Dept table
can no longer query or insert data into the 'Emp' table, but it may still have other privileges (such
as UPDATE or DELETE) if granted previously.
44