DBMS Lab Manual BCS403
DBMS Lab Manual BCS403
************************************************
Name
USN
Section
Lab Batch
Day / Time
************************************************
2023-2024 1
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 1:
AIM:
Create a table called Employee & execute the following.
Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
1. Create a user and grant all permissions to the user.
2. Insert the any three records in the employee table contains attributes EMPNO, ENAME JOB,
MANAGER_NO, SAL, COMMISSION and use rollback. Check the result.
3. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result.
DESIGN:
TABLE NAME: employee
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
EMPNO Number (number) 32-bit integer empno number(10)
ENAME Character (VARCHAR2) 10 Characters ename varchar2(10)
JOB Character (VARCHAR2) 10 Characters job varchar2(10)
MANAGER_NO Number (number) 32-bit integer manager_no number(10)
SAL Number (number) 32-bit integer sal number(10)
COMMISSION Number (number) 32-bit integer commission number(10)
2023-2024 2
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
Drop the table created
SQL> DROP TABLE employee;
P2. Insert the any three records in the employee table contains attributes EMPNO, ENAME JOB,
MANAGER_NO, SAL, COMMISSION and use rollback. Check the result.
SOLUTION:
SYNTAX:
INSERT INTO table (column1, column2, ... column_n ) VALUES (expression1, expression2, ...
expression_n );
2023-2024 3
DATABASE MANAGEMENT SYSTEM BCS403
SQL>
1. insert into employee (empno, ename, job, manager_no, sal, commission)
values(1,'Abhi','Manager',1,20000,1000);
P3. Add primary key constraint and not null constraint to the employee table.
SOLUTION:
To add NOT NULL constraint to existing column to the employee table.
SYNTAX: ALTER TABLE tablename MODIFY columnname NOT NULL NOVALIDATE;
SQL>
2023-2024 4
DATABASE MANAGEMENT SYSTEM BCS403
P4: Insert null values to the employee table and verify the result.
To Insert null values, use the insert command and pass the column value as null. Only NULLABLE
columns accept the null values.
SQL>
1. insert into employee (empno, ename, job, manager_no, sal, commission)
values(5,'Kumar','Admin',NULL,NULL,NULL);
2. insert into employee (empno, ename, job, manager_no, sal, commission) values (6,'Suhan’, NULL,
NULL, NULL, NULL);
3. insert into employee (empno, ename, job, manager_no, sal, commission) values (7, NULL, NULL,
NULL, NULL, NULL);
Verify the Result
SQL> select * from employee;
2023-2024 5
DATABASE MANAGEMENT SYSTEM BCS403
Conclusion:
All the queries as described in the experiment 1 is executed on the oracle 10g DBMS system. The results
are recorded and verified. The modification for the queries is also executed to understand the complete
importance of the CREATE, INSERT and SELECT SQL queries.
2023-2024 6
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 2:
AIM:
Create a table called Employee that contain attributes EMPNO, ENAME, JOB, MGR, SAL &execute
the following.
1. Add a column commission with domain to the Employee table.
2. Insert any five records into the table.
3. Update the column details of job
4. Rename the column of Employ table using alter command.
5. Delete the employee whose Empno is 105.
DESIGN:
TABLE NAME: employee
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
EMPNO Number (number) 32-bit integer empno number(10)
ENAME Character (VARCHAR2) 10 Characters ename varchar2(10)
JOB Character (VARCHAR2) 10 Characters job varchar2(10)
MGR Number (number) 32-bit integer mgr number(10)
SAL Number (number) 32-bit integer sal number(10)
2023-2024 7
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 8
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
Check the result of insertion of rows into the employee table.
SQL> select * from employee;
2023-2024 9
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
Check the result of updated rows in the employee table.
SQL> select * from employee;
2023-2024 10
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
Check the result of altered column in the employee table.
SQL> desc employee;
Practice Query:
Check the result of deleted row in the employee table.
SQL> select * from employee;
2023-2024 11
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 3:
AIM:
Queries using aggregate functions (COUNT, AVG, MIN, MAX, SUM), Group by, Order by.
Employee (E_id, E_name, Age, Salary)
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
2. Count number of employee names from employee table
3. Find the Maximum age from employee table.
4. Find the Minimum age from employee table.
5. Find salaries of employee in Ascending Order.
6. Find grouped salaries of employees.
DESIGN:
TABLE NAME: employee
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
EMPNO Number (number) 32-bit integer empno number(10)
ENAME Character (VARCHAR2) 10 Characters ename varchar2(10)
age Number (number) 32-bit integer age number(10)
SAL Number (number) 32-bit integer sal number(10)
2023-2024 12
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
Check the result of the employee table.
SQL> desc employee;
Practice Query:
Check the result of insertion of rows in the employee table.
SQL> select * from employee;
2023-2024 13
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 14
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
SQL> select avg(age) from employee;
Practice Query:
Find salaries of employee in DescendingOrder.
SQL> select ename,sal from employee order by sal desc;
2023-2024 15
DATABASE MANAGEMENT SYSTEM BCS403
Practice Query:
Find employee name and salaries of employee whose age is below 40 and salary is above 5000.
SQL> select ename, sal from employee where age<40 group by ename, sal having sal>5000;
2023-2024 16
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 4:
AIM:
Create a row level trigger for the customers table that would fire for INSERT or UPDATE or
DELETE operations performed on the CUSTOMERS table. This trigger will display the salary
difference between the old & new Salary.
CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY)
DESIGN:
TABLE NAME: customers
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
ID Number (number) 32-bit integer id number(10)
NAME Character (VARCHAR2) 30 Characters name varchar2(30)
AGE Number (number) 32-bit integer age number(10)
ADDRESS Number (number) 32-bit integer address varchar2(50)
SALARY Number (number) 32-bit integer salary number(10)
PRE QUERIES:
Create a table called customers & execute the following.
customers (ID, NAME, AGE, ADDRESS, SALARY)
SOLUTION:
SQL> create table customers (id number(10), name varchar2(30), age number(10), address varchar2(50),
salary number(10));
2023-2024 17
DATABASE MANAGEMENT SYSTEM BCS403
2. insert into customers (id, name, age, address, salary) values(102,'Rohan',42, 'Tumkuru', 10000);
3. insert into customers (id, name, age, address, salary) values(103,'Kumar',38, 'Belagavi', 9000);
4. insert into customers (id, name, age, address, salary) values(104,'Chandu',35, 'Tiptur ', 9000);
5. insert into customers (id, name, age, address, salary) values(105,'Keerthi',36, 'Mangaluru',9000);
Practice Query:
Check the result of insertion of rows in the employee table.
SQL> select * from employee;
2023-2024 18
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 19
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 5:
AIM:
Create cursor for Employee table & extract the values from the table. Declare the variables, Open
the cursor & extract the values from the cursor. Close the cursor.
Employee(E_id, E_name, Age, Salary)
DESIGN:
TABLE NAME: employee
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
E_ID Number (number) 32-bit integer e_id number(10)
E_NAME Character (VARCHAR2) 30 Characters e_name varchar2(30)
AGE Number (number) 32-bit integer age number(10)
SALARY Number (number) 32-bit integer salary number(10)
PRE QUERIES:
Create a table called customers & execute the following.
employee (E_ID,E_NAME, AGE, SALARY)
SOLUTION:
SQL> create table employee (e_id number(10), e_name varchar2(30), age number(10), salary
number(10));
2023-2024 20
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 21
DATABASE MANAGEMENT SYSTEM BCS403
BEGIN
OPEN emp_cursor;
LOOP
FETCH emp_cursor INTO v_e_id, v_e_name, v_age, v_salary;
EXIT WHEN emp_cursor%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('Employee ID: ' || v_e_id);
DBMS_OUTPUT.PUT_LINE('Employee Name: ' || v_e_name);
DBMS_OUTPUT.PUT_LINE('Employee Age: ' || v_age);
DBMS_OUTPUT.PUT_LINE('Employee Salary: ' || v_salary);
END LOOP;
CLOSE emp_cursor;
END;
2023-2024 22
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 6:
AIM:
Write a PL/SQL block of code using parameterized Cursor, that will merge the data availablein the
newly created table N_RollCall with the data available in the table O_RollCall. If the data in the first
table already exist in the second table, then that data should be skipped.
DESIGN:
TABLE NAME: N_RollCall
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
ROLL Number (number) 32-bit integer roll number(10)
NAME Character (VARCHAR2) 30 Characters name varchar2(30)
PRE QUERIES:
Create a table called N_RollCall & execute the following.
N_RollCall (ROLL,NAME)
SOLUTION:
SQL> create table N_RollCall (roll number(10), name varchar2(30));
2023-2024 23
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 24
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 25
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 26
DATABASE MANAGEMENT SYSTEM BCS403
EXPERIMENT 7:
AIM:
Install an Open Source NoSQL Data base MangoDB & perform basic CRUD (Create, Read, Update &
Delete) operations. Execute MangoDB basic Queries using CRUD operations.
DESIGN:
TABLE NAME: N_RollCall
Fields/Column Domain/Data Format (SQL Size Syntax
name keyword)
ROLL Number (number) 32-bit integer roll number(10)
NAME Character (VARCHAR2) 30 Characters name varchar2(30)
PROBLEM 1:
Install an Open Source NoSQL Data base MangoDB.
SOLUTION:
MongoDB is an open-source document-oriented database. It is categorized under the NoSQL(Not only
SQL) database because the storage and retrieval of data in MongoDB are not in the form of tables.
Requirements to Install MongoDB on Windows
MongoDB 4.4 and later only support 64-bit versions of Windows.
MongoDB 7.0 Community Edition supports the following 64-bit versions of Windows on x86_64
architecture:
Windows Server 2022
Windows Server 2019
Windows 11
Ensure that the user is running mongod and mongos has the necessary permissions from the following
groups:
Performance Monitor Users
2023-2024 27
DATABASE MANAGEMENT SYSTEM BCS403
Step 3: Now accept the End-User License Agreement and click the next button:
Step 4: Now select the complete option to install all the program features.
Step 5: Select “Run service as Network Service user” and copy the path of the data directory. Click
Next:
2023-2024 28
DATABASE MANAGEMENT SYSTEM BCS403
Step 6: Click the Install button to start the MongoDB installation process:
Step 8: Now click the Finish button to complete the MongoDB installation process:
Step 9: Now we go to the location where MongoDB installed in step 5 in your system and copy the bin
path:
2023-2024 29
DATABASE MANAGEMENT SYSTEM BCS403
Step 10: Now, to create an environment variable open system properties << Environment Variable <<
System variable << path << Edit Environment variable and paste the copied link to your environment
system and click Ok:
Step 11: After setting the environment variable, we will run the MongoDB server, i.e. mongod. So,
open the command prompt and run the following command:
mongod
When you run this command you will get an error i.e. C:/data/db/ not found.
Step 12: Now, Open C drive and create a folder named “data” inside this folder create another folder
named “db”. After creating these folders. Again open the command prompt and run the following
command:
mongod
Now, this time the MongoDB server(i.e., mongod) will run successfully.
2023-2024 30
DATABASE MANAGEMENT SYSTEM BCS403
PROBLEM 1:
Install an Open Source NoSQL Data base MangoDB.
SOLUTION:
SQL>
perform basic CRUD (Create, Read, Update & Delete) operations. Execute MangoDB basic Queries
using CRUD operations.
P1: CREATE OPERATION
SOLUTION:
Create a New Database Using Mongo Shell
use college
Show List of Databases
show dbs
Check Current Database
db
2023-2024 31
DATABASE MANAGEMENT SYSTEM BCS403
Create Operations
Method Description
db.collection.insertOne() It is used to insert a single document in the collection.
db.collection.insertMany() It is used to insert multiple documents in the collection.
db.createCollection() It is used to create an empty collection.
Exercise1:
Insert Single Document
db.student.insert({Name: "Akshay", Marks: 500})
db.student.find().pretty()
db.student.insertOne({Name: "Akshay", Marks: 500})
db.student.insertOne({_id: "Stu102", Name: "Vishal", Marks: 230})
db.student.insertMany([{name:"Ajay",age:20},
{name:"Bina",age:24},
{name:"Ram",age:23}])
db.student.insertMany([{_id:"stu200", name:"Ammu", age:18},
{_id:"stu201", name:"Priya", age:29}])
2023-2024 32
DATABASE MANAGEMENT SYSTEM BCS403
db.student.findOne({language:"c++"})
db.student.findOne({name: "Avinash"}, {_id: 0, language:1})
BASIC OPERATION1:
SOLUTION:
We will drop the student collection in the gfg database. It drops the student collection and all the indexes
associated with the collection:
db.student.drop()
BASIC OPERATION2:
SOLUTION:
MongoDB distinct() method finds the distinct values for a given field across a single collection and returns
the results in an array. It takes three parameters, first one is the field for which to return distinct values
and the others are optional.
2023-2024 33
DATABASE MANAGEMENT SYSTEM BCS403
db.student.distinct("name")
db.student.distinct("detail.age")
db.student.distinct("marks")
BASIC OPERATION3:
SOLUTION:
In MongoDB, the limit() method limits the number of records or documents that you want. It basically
defines the max limit of records/documents that you want. Or in other words, this method uses on cursor
to specify the maximum number of documents/ records the cursor will return.
db.gfg.find().limit(2)
db.gfg.find({"content":/c/i}).limit(2)
Here, content is key were we will check whether it contains ‘c’ character in the string or not. /c/ denotes
that we are looking for strings that contain this ‘c’ character and in the end of /c/i, i denotes that it is case-
insensitive.
db.gfg.find({"content":/c/i}).limit(3)
2023-2024 34
DATABASE MANAGEMENT SYSTEM BCS403
BASIC OPERATION4:
SOLUTION:
MongoDB provides a createIndex() method to create one or more indexes on collections. Using this
method we can create different types of indexes like text index, 2dsphere index, 2d index, etc.
db.student.createIndex({name:1})
db.student.createIndex({language:-1})
db.student.createIndex({name:1,language:-1})
db.student.createIndex({name:1},{unique:true})
db.student.createIndex({"branch.$**":1})
BASIC OPERATION5:
SOLUTION:
MongoDB – Comparison Query Operators
Operators Description
$eq Matches the values of the fields that are equal to a specified value.
$ne Matches all values of the field that are not equal to a specified value.
$gt Matches values of the fields that are greater than a specified value.
$gte Matches values of the fields that are greater than equal to the specified value.
$lt Matches values of the fields that are less than a specified value
$lte Matches values of the fields that are less than equal to the specified value
$in Matches any of the values specified in an array.
$nin Matches none of the values specified in an array.
2023-2024 35
DATABASE MANAGEMENT SYSTEM BCS403
2023-2024 36
VIVA QUESTIONS AND ANSWERS
1. What is database?
A database is a collection of information that is organized. So that it can easily be accessed,
managed, and updated.
2. What is DBMS?
DBMS stands for Database Management System. It is a collection of programs that enables
user to create and maintain a database.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. What are the advantages of DBMS?
I. Redundancy is controlled.
II. Providing multiple user interfaces.
III. Providing backup and recovery
IV. Unauthorized access is restricted.
V. Enforcing integrity constraints.
5. What is normalization?
It is a process of analysing the given relation schemas based on their Functional
Dependencies (FDs) and primary key to achieve the properties
(1).Minimizing redundancy, (2). Minimizing insertion, deletion and update anomalies.
6. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and
constraints.
7. What is E-R model?
This data model is based on real world that consists of basic objects called entities and of
relationship among these objects. Entities are described in a database by a set of
attributes.
8. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance
variables with in the object. An object also contains bodies of code that operate on the
object. These bodies of code are called methods. Objects that contain same types of values
and the same methods are grouped together into classes.
9. What is an Entity?
An entity is a thing or object of importance about which data must be captured.
10. What is DDL (Data Definition Language)?
A data base schema is specifies by a set of definitions expressed by a special language
called DDL.
11. What is DML (Data Manipulation Language)?
This language that enable user to access or manipulate data as organized by appropriate
data model. Procedural DML or Low level: DML requires a user to specify what data are
needed and how to get those data. Non-Procedural DML or High level: DML requires a
user to specify what data are needed without specifying how to get those data
12. What is DML Compiler?
It translates DML statements in a query language into low-level instruction that the query
evaluation engine can understand.
13. What is Query evaluation engine?
It executes low-level instruction generated by compiler.
14. Under what conditions should indexes be used?
Indexes can be created to enforce uniqueness, to facilitate sorting, and to enable fast
retrieval by column values. A good candidate for an index is a column that is frequently
used with equal conditions in WHERE clauses.
15. What is difference between SQL and SQL SERVER?
SQL is a language that provides an interface to RDBMS, developed by IBM. SQL SERVER is
a RDBMS just like Oracle, DB2.