DBMS Lab Manual
DBMS Lab Manual
LAB MANUAL
For
DBMS (BCA-505)
Prepared by
Department of Computer Application
Session – 2021-22
Course Objectives:
Course Outcomes:
The students should be able to:
03
Write SQL query using group by function.
04
Write SQL queries for group functions.
05
Write SQL queries for sub queries, nested queries.
06
Write SQL queries to create views.
07
Write an SQL query to implement JOINS.
09
Write program by the use of PL/SQL
AIM:
Write the queries for Data Definition Language and Data Manipulation Language.
Explanation:
DDL:
a. CREATE
b. DROP
c. TRUNCATE
d. RENAME
e. ALTER
DDL COMMANDS:
SYNTAX:
ALTER Statement:
a. INSERT
b. UPDATE
c. DELETE
d. SELECT
DML COMMANDS:
SYNTAX:
INSERT Statement:
Multiple Row into a Table: insert into <table name> values (&col1, &col2, ….);
Q1. Write a query to create a table employee with empno, ename, designation, and salary.
Table created.
Q2. Write a query for create a from an existing table with all the fields.
Table created.
Q3. Write a Query to Alter the column EMPNO NUMBER (4) TO EMPNO NUMBER (6).
Table altered.
Table altered.
Table altered.
Q6. Write a query to drop an existing table employee.
Table deleted.
DML QUERIES:
1 row created.
Q3. Write a query to insert the records in to employee using substitution method.
1 row created.
SQL> /
Enter value for empno: 101
1 row created.
1 row updated.
Outcome:
To understand the basic commands of DML and DDL and their use in database.
Experiment No. – 2
AIM:
Explanation:
Arithmetic operators
Comparison operators
Logical operators
Q1. Write a query to find the salary of a person where age is <= 26 and salary >= 25000 from
customer table.
SQL>SELECT * FROM CUSTOMERS WHERE AGE <= 26 AND SALARY >= 25000;
Output:
Q2. Write a query to find the salary of a person where age is <= 26 or salary > =33000 from
customer table.
SQL>SELECT * FROM CUSTOMERS WHERE AGE <= 26 or SALARY > =33000;
Output:
5 rows selected
Q3.Write a query to find the name of customer whose name is like “Ku%”.
Output:
1 row selected
Q4. Write a query to find the customer details using “IN” and “Between” operator where age can
be 25 or 27.
Output:
2 rows selected
Outcome:
To understand the implementation of SQL queries using logical operations and operators.
Experiment No. – 3
AIM:
Explanation:
The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN,
SUM, AVG) to group the result-set by one or more columns.
GROUP BY Syntax:
QUERY:
Output:
COUNT(ID) ADDRESS
2 Delhi
1 Mumbai
1 Kolkata
1 Hyderabad
1 Chennai
1 Noida
6 rows selected
Outcome:
Explanation:
To use a group function in a SQL query, list the function name followed by numeric column
name within parentheses. AVG averages the column, COUNT counts the number of items, MAX
returns maximum number of the column, and MIN returns minimum number of the column .The
following is query to retrieve total price, average price, maximum price, and minimum price
from the table “product” assuming the product table has the following values.
QUERY:
PRODUCT TABLE
SUM (PRICE)
870
This statement will returns the total amount for the column price which is 870.
Avg (price)
217.50
This statement will returns the average amount for the column price which is 870/4 or
217.50.
Q3. Write a query find the max price of the product.
Max (price)
300
This statement will returns the maximum amount for the column price which is 300.
Outcome:
3. Outer Join: It extends the result of a simple join. An outer join returns all the rows returned
by simple join as well as those rows from one table that do not match any row from the table.
The symbol (+) represents outer joins.
4. Inner Join: Inner join returns the matching rows from the tables that are being joined
1 Mathi AP 1 30000
4 Karthik AP 1 35000
Q1. Display all employee names and salary whose salary is greater than minimum salary of the
company and job title starts with „A‟.
SQL>select ename, sal from emp where sal > (select min(sal) from emp where job like 'A%');
Output:
ENAME SALARY
Arjun 32000
Gugan 40000
Karthik 35000
3 rows selected.
Outcome:
QUERIES:
EMPLOYEE TABLE
DEPARTMENT TABLE
Output:
4 rows selected
Outcome:
To understand the implementation of JOINS using SQL.
Experiment No. – 8
AIM:
Write a query for extracting data from more than one table.
Query:
EMPLOYEE TABLE
DEPARTMENT TABLE
Q1. Write a query to extract empno, ename, salary, dname and location from employee and
department table where empno = deptno without using joins.
2 rows selected
Q2. Write a query to extract ename, salary and location from employee and department table
where is like 30, 40.
SQL> select employee.ename, employee.salary, department.location
From department, employee
Where department.deptno IN (30, 40);
Output:
No rows Selected.
Outcome:
To understand the queryfor extracting data from more than one table.
Experiment No. – 9
AIM:
Write programme by the use of PL/SQL.
Explanation:
The PL/SQL programming language was developed by Oracle Corporation in the late
1980s as procedural extension language for SQL and the Oracle relational database. PL/SQL has
the following features −
PL/SQL is tightly integrated with SQL.
Query:
DECLARE
a number (2) := 21;
b number (2) := 10;
BEGIN
IF (a = b) then
dbms_output.put_line('Line 1 - a is equal to b');
ELSE
dbms_output.put_line('Line 1 - a is not equal to b');
END IF;
IF (a < b) then
dbms_output.put_line('Line 2 - a is less than b');
ELSE
dbms_output.put_line('Line 2 - a is not less than b');
END IF;
IF ( a> b ) THEN
dbms_output.put_line('Line 3 - a is greater than b');
ELSE
dbms_output.put_line('Line 3 - a is not greater than b');
END IF;
END;
Output:
Line 1 - a is not equal to b
Line 2 - a is not less than b
Line 3 - a is greater than b
Outcome:
To learn the programming using PL/SQL.
Experiment No. – 10
AIM:
Write a query to understand the concepts for ROLL BACK, COMMIT & CHECK
POINTS.
Explanation:
Transaction Control Language (TCL) commands are used to manage transactions in
database. These are used to manage the changes made by DML statements. It also allows
statements to be grouped together into logical transactions.
Commit Command
Commit command is used to permanently save any transaction into database.
Following is Commit command's syntax:
SQL> COMMIT;
Rollback Command
This command restores the database to last committed state. It is also use with savepoint
command to jump to a savepoint in a transaction.
Following is Rollback command's syntax:
SQL> rollback to savepoint-name;
Savepoint command
Savepoint command is used to temporarily save a transaction so that you can rollback to that
point whenever necessary.
Following is savepoint command's syntax:
SQL> savepoint savepoint-name;
QUERY:
Q1. Write a query to implement the save point.
SQL> select employee.empno, employee.ename, employee.salary, department.dname,
department.location
From department, employee
Where department.deptno = employee.empno;
SQL> SAVEPOINT S1;
Savepoint Created.
Outcome:
Date_of_join Date
Varchar2(30
Designation
)
Salary Number(9,2)
Reference
Deptno Number(2)
key
Deptt
Deptno Number(2)
Varchar2(30
Dname Not null
)
Varchar2(30
Dloc
)
LAB 1
create table neetu11(empno number(5), empname varchar2(30), date_of_join date, designation
varchar(30), salary number(9,2), deptno number(2));
LAB 3
Alter table neetu11 add(mobno number(10))
LAB 4
Desc neetu11
lab 5
lab 6