DBMS Lab Manual
DBMS Lab Manual
TECHNOLOGY
BDFT. SEM-4
DATABSE MANAGEMENT
SYSTEM
LAB MANUAL
1. Introduction to SQL
2. Basic database related operations on MYSQL
3. Design a garments store database with required tables and
constraints
6. Write SQL query to create copy of a table (along with data), and
drop that copy
INDEX
INTRODUCTION TO SQL
QUES. Introduction to SQL
a. About DDL,DML,DCL,TCL
b. SQL data types
c. SQL operators
DDL- Data Definition Language. DDL is used for specifying the database schema. It is
used for creating tables, schema, indexes, constraints etc. in database.
DML- Data Manipulation Language. DML is used for accessing and manipulating
data in a database.
DCL- Data Control language. DCL is used for granting and revoking user access on
a database.
TCL- Transaction Control Language. The changes in the database that we make
using DML commands are either performed or rollbacked using TCL.
SQL OPERATORS-
ARITHMETIC OPEARTORS-
OPERATOR DESCRIPTION
+ Add
_ Subtract
* Multiply
/ Divide
% Modulo
BITWISE OPERATORS-
OPERATOR DESCRIPTION
| Bitwise OR
^ Bitwise Exclusive OR
COMPARISION OPERATORS-
OPERATOR DESCRIPTION
= Equal to
COMPOUND OPERATORS-
OPERATOR DESCRIPTION
+= Add equals
-= Subtract equals
*= Multiply equals
/= Divide equals
%= Modulo equals
LOGICAL OPERATORS-
OPERATOR DESCRIPTION
QUES.
Design the following tables in garment_store database along with constraints like
Primary Key, Foreign key, NOT NULL, and check constraint to the tables.
- product(product_id, Pname, brand, season, price)
- purchase(purchase_id, item_id, no_of_items, amount, purchase_date)
- stock(item_id, instock, status)
- sales(sale_id, item_id, no_of_items_sold, sale_rate, amount, date_of_sale)
QUES
Write SQL statement for implementing ALTER, DROP at column level in Q3 tables.
a. ADD (e.g.: add a column “status” in stock table(if not present))
b. MODIFY
c. RENAME
d. DROP
QUES
Perform following operations on tables in Q3
a. populate with few tuples as per specified constraints, and
b. display all tuples(data)
QUES
Write SQL query to
a. Create a copy of “product” table(along with data), and
b. Drop that copy
QUES
Write SQL query to implement all aggregate functions: MAX(), MIN(), AVG(),
COUNT(), SUM() (eg: on price column of product table)
MIN-
SELECT MIN(Price) AS SmallestPrice
FROM Products;
MAX-
SELECT MAX(sales_amount) AS HighestPrice
FROM sales;
COUNT-
SELECT COUNT(Product_id)
FROM Products;
AVG-
SELECT AVG(price)
FROM Products;
SUM-
SELECT SUM(no_of_items)
FROM Purchase;
BASIC DBMS OPERATIONS
6. Write a query to get the records from emp table where deptno is 10 or salary is
greater than 2000.
SELECT * FROM emp
WHERE deptno= 10 OR sal>2000;
7. Write SQL query to select only distinct deptno from emp table.
SELECT DISTINCT deptno FROM emp;
8. Write SQL query to display the Ename starting with s,a or m in table employee.
SELECT * FROM emp
WHERE ename LIKE 'S%' OR ename LIKE 'A%' OR ename LIKE 'M%';
9. Write SQL query to display name of employees in descending order.
SELECT ename FROM emp
ORDER BY ename DESC;
10. Write SQL query to change the name of smith to “johnson” in employee table.
UPDATE emp
SET ename = 'Johnson'
WHERE ename = 'SMITH';
SELECT * FROM emp;
11. Write SQL query to display only top 5 rows from employee table.
SELECT * FROM emp
FETCH FIRST 5 ROWS ONLY;
12. Write SQL query to select all the employees name whose deptno is 10 and
20(using IN operator).
SELECT ename FROM emp
WHERE deptno IN (10, 20);
13. Write SQL query to select the records from emp table whose salary is in the
range of 1500 to 3000(using BETWEEN operator).
SELECT * FROM emp
WHERE sal BETWEEN 1500 AND 3000;
14. Delete the record of an employee from emp table whose name is ‘Ford’.
Before deletion-
After deletion-
15. Apply all 4 joins on employee table and dept table(inner, left, right, outer) and
show the resultant tables.
emp table-
dept table-
INNER JOIN:
SELECT emp.ename, emp.empno, emp.job, emp.sal , dept.dname
FROM emp
INNER JOIN dept ON emp.deptno = dept.deptno;
LEFT JOIN:
SELECT emp.ename, emp.empno, emp.job, emp.sal , dept.dname
FROM emp
LEFT JOIN dept ON emp.deptno = dept.deptno;
RIGHT JOIN:
SELECT emp.ename, emp.empno, emp.job, emp.sal , dept.dname
FROM emp
RIGHT JOIN dept ON emp.deptno = dept.deptno;
FULL OUTER JOIN:
SELECT emp.ename, emp.empno, emp.job, emp.sal , dept.dname
FROM emp
FULL OUTER JOIN dept ON emp.deptno = dept.deptno;
16. Write SQL query to list the no of employees in each department(use Group
By)
SELECT COUNT(empno), deptno
FROM emp
GROUP BY deptno;
UNION OPERATOR