DBMS LAB PROGRAMS
DBMS LAB PROGRAMS
1.Creation, altering and droping of tables and inserting rows into a table (use
constraints while creating tables) examples using SELECT command.
1. Create Table with Constraints
Create a table Employees with constraints like PRIMARY KEY, NOT NULL, and UNIQUE:
UPDATE Employees
SET DateOfJoining = '2023-03-01'
WHERE EmployeeID = 102;
UPDATE Employees
SET DateOfJoining = '2021-07-20'
WHERE EmployeeID = 103;
5. Drop a Table
2. Queries (along with sub Queries) using ANY, ALL, IN, EXISTS,
NOTEXISTS, UNION, INTERSET, Constraints. Example:- Select the roll
number and name of the student who secured fourth rank in the class.
WHERE NOT EXISTS (SELECT 1 FROM Students WHERE Marks < 80 AND RollNumber = s.RollNumber);
9. Using UNION
Combine students scoring above 90 and those ranked in the top 2:
SELECT Name, Marks FROM Students WHERE Marks > 90
UNION
SELECT Name, Marks FROM Students WHERE Rank <= 2;
10. Using INTERSECT
Find students scoring above 85 who are also ranked in the top 3:
SELECT Name FROM Students WHERE Marks > 85
INTERSECT
SELECT Name FROM Students WHERE Rank <= 3;
______________________________________________________________________________
3.Queries using Aggregate functions (COUNT, SUM, AVG, MAX and MIN),
GROUP BY, HAVING and Creation and dropping of Views.
Example Queries:
● GROUP BY: Find the total quantity sold for each product.
Creating a View: You can create a view to simplify complex queries. For example, create a
view to get the total revenue per product:
Dropping a View: If you no longer need the view, you can drop it:
Find the total sales revenue and average price for each product, but only for products with
total sales greater than $2000: