DBMS File (2023UCA1952)
DBMS File (2023UCA1952)
DBMS File (2023UCA1952)
Lab Assignments
Sahaj Sharma
2023UCA1952
CSAI-II
1. Create the table as employee and the details are :-
QUERY:-
CREATE TABLE IF NOT EXISTS Employees (
S_no INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Designation VARCHAR(50),
Branch VARCHAR(20)
);
INSERT INTO Employees VALUES
(1,"Ram","Manager","Chennai"),
(2,"Santosh","Supervisor","Madurai"),
(3,"Hari","Assistant","Trichy");
● Alter the table by adding a column Salary
QUERY:-
ALTER TABLE Employees ADD COLUMN Salary INT;
UPDATE Employees SET Salary = 45000 WHERE S_no=1;
UPDATE Employees SET Salary = 55000 WHERE S_no=2;
UPDATE Employees SET Salary = 50000 WHERE S_no=3;
B)SELECT *
FROM EMPLOYEES
WHERE Manager_Id = 100;
C)SELECT First_Name,Last_Name
FROM EMPLOYEES
WHERE Salary>=4800;
D)SELECT *
FROM EMPLOYEES
WHERE Last_Name=’AUSTIN’;
E)SELECT First_Name,Last_Name
FROM EMPLOYEES
WHERE Department_Id IN (60,70,80);
A)
B)SELECT Name
FROM Client_Master
WHERE Balance_Due>5000;
-- (b) Find names of sailors who've reserved a red or a green boat in the month of
March
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' OR b.color = 'green')
AND MONTH(r.date) = 3;
-- (c) Find names of sailors who've reserved a red and a green boat
SELECT DISTINCT s.sname
FROM SAILORS s
WHERE EXISTS (
SELECT 1
FROM RESERVES r1
JOIN BOATS b1 ON r1.bid = b1.bid
WHERE s.sid = r1.sid AND b1.color = 'red'
) AND EXISTS (
SELECT 1
FROM RESERVES r2
JOIN BOATS b2 ON r2.bid = b2.bid
WHERE s.sid = r2.sid AND b2.color = 'green'
);
Lab 4
1.Create the following table.
Create an employee’s table with the given fields and data in the table.
f. Find the names of employees who work in departments 60, 70, and 80:
g. Display the unique Manager_Id:
2.Create a customer’s table with the given fields and data in the table. The name of the table
should be CUSTOMERS.
a.Retrieve each and every record in table format.
c.List out all the consumers having salary between 6000 and 9000.
d.Insert a new column “Product” into the table and show the table.
e.Delete the newly created column “Product” and show the updated table.
j.Retrieve all rows from the table where the age is equal to 25 or the salary is less than 4500
and the name is either Gayatri or Raushan.
LAB 5
Consider the following relation:
Write an SQL query to find the position of the alphabet (‘a’) in the
first name column ‘Amitabh’ from the Worker table.
Write an SQL query to print the FIRST_NAME from the Worker table
after removing white spaces from the right side.
Write a query to fetch all employees who also hold the managerial position.
Write a query to retrieve two minimum and maximum salaries from
the EmployeePosition table.
a) Find the names of the customer who have purchased no item. Set default value of
Cust_balance as 0 for such customers.
b) Write the trigger to update the CUST_BALANCE in the CUSTOMER table when a new
invoice record is entered for the customer.
c) Find the customers who have purchased more than three units of a product on a day.
d) Write a query to illustrate Left Outer, Right Outer and Full Outer Join.
e) Count number of products sold on each date.
f) As soon as customer balance becomes greater than Rs. 100,000, copy the
customer_num in new table called ”GOLD_CUSTOMER”