DBMS File (2023UCA1952)

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

DBMS

Lab Assignments
Sahaj Sharma
2023UCA1952
CSAI-II
1. Create the table as employee and the details are :-

S.no Name Designation Branch


1. Ram Manager Chennai
2. Santosh Supervisor Madurai
3. Hari Assistant Trichy

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;

● Alter the table by modifying the column Name


QUERY:-
ALTER TABLE Employees RENAME COLUMN Name TO
Full_Name;
● Describe the table employee
QUERY:-
DESC Employees;

● Copy the table employee as emp


QUERY:-
CREATE TABLE emp AS SELECT * FROM Employees;
SELECT * FROM emp;
● Truncate the table
QUERY:-
TRUNCATE TABLE Employees;

● Delete the Second row from the table


QUERY:-
DELETE FROM emp WHERE S_no=2;
SELECT * FROM emp;

● Drop the Table


QUERY:-
DROP emp;
Assignment 2
QUESTION 1:-

A)SELECT Employee_Id,First_Name,Last_Name,Salary FROM EMPLOYEES;

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);

F)SELECT DISTINCT Manager_Id


FROM EMPLOYEES;
QUESTION 2:-

A)

B)SELECT Name
FROM Client_Master
WHERE Balance_Due>5000;

C)UPDATE Client_Master SET Balance_Due = 5100 WHERE Client_no = “C123”;

D)RENAME Client_Master to Client12;


E)SELECT Client_No, Balance_Due AS Balance from Client_Master;
Assignment 3
QUESTION :-

-- Step 1: Create the SAILORS table


CREATE TABLE SAILORS (
sid INT PRIMARY KEY,
sname VARCHAR(50),
rating INT,
date_of_birth DATE
);

-- Step 2: Create the BOATS table


CREATE TABLE BOATS (
bid INT PRIMARY KEY,
bname VARCHAR(50),
color VARCHAR(20)
);

-- Step 3: Create the RESERVES table


CREATE TABLE RESERVES (
sid INT,
bid INT,
date DATE,
time_slot VARCHAR(20),
FOREIGN KEY (sid) REFERENCES SAILORS(sid),
FOREIGN KEY (bid) REFERENCES BOATS(bid)
);

-- Step 4: Insert sample data into the SAILORS table


INSERT INTO SAILORS (sid, sname, rating, date_of_birth)
VALUES
(1, 'John', 5, '1980-02-15'),
(2, 'Mike', 7, '1985-05-20'),
(3, 'Sara', 8, '1990-10-10'),
(4, 'Bob', 6, '1982-12-02'),
(5, 'Anna', 9, '1992-07-11');

-- Step 5: Insert sample data into the BOATS table


INSERT INTO BOATS (bid, bname, color)
VALUES
(1, 'Speedster', 'red'),
(2, 'Wave Rider', 'green'),
(3, 'Sun Chaser', 'blue'),
(4, 'Sea Queen', 'red'),
(5, 'Ocean Breeze', 'green');

-- Step 6: Insert sample data into the RESERVES table


INSERT INTO RESERVES (sid, bid, date, time_slot)
VALUES
(1, 1, '2023-03-15', 'Morning'),
(1, 2, '2023-03-16', 'Evening'),
(2, 3, '2023-01-10', 'Afternoon'),
(2, 4, '2023-03-15', 'Morning'),
(3, 5, '2023-03-18', 'Evening'),
(4, 1, '2018-01-20', 'Morning'),
(4, 2, '2018-01-21', 'Evening'),
(5, 4, '2020-07-15', 'Afternoon');

-- Step 7: Execute the required queries

-- (a) Find sailors who've reserved at least one boat


SELECT DISTINCT s.sid, s.sname
FROM SAILORS s
JOIN RESERVES r ON s.sid = r.sid;

-- (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.

a. Retrieve each and every record in table format:


b. Find out the employee id, names, and salaries of all employees:

c. List out the employees who work under manager 100:


d. Find the names of employees who have a salary greater than or equal to 4800:

e. List out the employees whose last name is 'AUSTIN':

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.

b.Rename the table from CUSTOMERS to CONSUMERS.

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.

f.Update the ADDRESS for a customer where ID = 5.

g.Retrieve the names of customer who is having age = 22 Address= Bhopal.


h.Retrieve the names of customer who is having age 22 and 25.

i.Delete the record of a customer who is having id= 4.

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 fetch “FIRST_NAME” from the Worker table


in upper case.

Write an SQL query to fetch unique values of DEPARTMENT from


the Worker table.

Write an SQL query to print the first three characters of


FIRST_NAME from the Worker table.

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 an SQL query to print details of Workers with DEPARTMENT


name as “Admin
Consider the following two tables

-> Write a query to fetch the department-wise count of employees sorted by


department’s count in ascending order.

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.

Consider the following table.


WRITE A QUERY TO RETRIEVE THE LIST OF PATEINTS FROM THE SAME STATE.

WRITE A QUERY TO FETCH TOP N RECORDS USING THE TOP/LIMT ORDERED BY


CONSULTATION
Lab 6
Consider the following relational schema
DEPARTMENT(Department_ID, Name, Location_ID)
JOB (Job_ID , Function )
EMPLOYEE (Employee_ID, name, DOB, Job_ID , Manager_ID, Hire_Date, Salary,
department_id)
a) Write a query to count number of employees who joined in March 2015

b) Display the Nth highest salary drawing employee details.

c) Find the budget (total salary) of each department.

d)Find the department with maximum budget.

Consider the following relational schema:


CUSTOMER (cust_num, cust_lname , cust_fname, cust_balance);
PRODUCT (prod_num, prod_name, price);
INVOICE (inv_num, prod_num, cust_num, inv_date ,unit_sold, inv_amount);
Write SQL queries expression for the following

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”

g) Add a new attribute CUST_DOB in customer table

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy