DBMS Lab Workbook
DBMS Lab Workbook
(CSL 214)
Lab Workbook
Roll No.:
Semester: III
Group:
Session 2025-26
DBMS Lab Workbook (CSL214) | 2
2025-26
INDEX
Experiment No: 1
Student Name and Roll Number: Sara Sharma 24CSU184
DBMS Lab Workbook (CSL214) | 4
2025-26
Link to Code:
Date: 20/08/2025
Faculty Signature:
Marks:
Objective
Design an ER/EER diagram for the COMPANY and SPORTS TEAM database.
Program Outcome
The students will be able to draw conceptual database design using ERD Plus.
Problem Statement
1. The COMPANY database keeps track of a company’s employees, departments, and projects.
Suppose that after the requirements collection and analysis phase, the database designers provide
the following description of the mini world—the part of the company that will be represented in
the database.
same department. We keep track of the current number of hours per week
that an employee works on each project. We also keep track of the direct
supervisor of each employee (who is another employee).
We want to keep track of the dependents of each employee for insurance
purposes. We keep each dependent’s first name, sex, birth date, and relationship to the
employee.
2. Design an ER/EER diagram for keeping track of the exploits of your favourite sports team.
You should store the matches played, the scores in each match, the players in each match and
individual player statistics for each match. Summary statistics should be modelled as derived
attributes. Further, extend the E-R diagram of the previous question to track the same
information for all teams in a league.
Design the ER/EER model by identifying the following from the above requirements:
Background Study
1) Entity:
o Real-world object distinguishable from other objects.
o An entity is described using a set of attributes.
3) Attributes
o Attributes are properties used to describe an entity.
o Example: EMPLOYEE entity may have a Name, SSN, Address, Sex, BirthDate.
4) Relationship
o A relationship relates two or more distinct entities with a specific meaning.
o Relationships of the same type are grouped or typed into a relationship type.
o 3 types of relationships : Unary, Binary & Ternary.
5) Recursive Relationship
o A relationship with the same participating entity type in distinct roles.
o Example: the SUPERVISION relationship
6) Structural Constraints – Semantics of Relationships
o Cardinality Ratio : The number of instances of an entity from a relation that can
be associated with the relation.
o Participation Constraints
Total Participation − Each entity is involved in the relationship.
Partial participation − Not all entities are involved in the relationship.
DBMS Lab Workbook (CSL214) | 7
2025-26
ER Diagram
DBMS Lab Workbook (CSL214) | 8
2025-26
DBMS Lab Workbook (CSL214) | 9
2025-26
Preparatory Questions
Q1) Given the basic ER and relational models, which of the following is INCORRECT?
Q2) Consider a directed line(-->) from the relationship set advisor to both entity sets instructor
and student. This indicates _________ cardinality
1) One to many
2) One to one
3) Many to many
4) Many to one
Q3) An entity set that does not have sufficient attributes to form a primary key is termed as :
1) Strong entity set
2) Variant set
3) Weak entity set
4) Variable set
Q4) Which of the following indicates the maximum number of entities can be involved in a
relationship?
1) Minimum cardinality
2) Maximum Cardinality
3) ERD
4) Greater Entity Count (GEC)
DBMS Lab Workbook (CSL214) | 10
2025-26
Q5) State true or false: Every weak entity must be associated with and identifying entity.
1) True
2) False
DBMS Lab Workbook (CSL214) | 11
2025-26
Experiment No: 2
Student Name and Roll Number: Sara Sharma 24CSU184
Link to Code:
Date: 20/08/2025
Faculty Signature:
Marks:
Objective
Design a Relational Database Schema for the COMPANY and SPORTS TEAM database from
the ER/EER diagram.
Program Outcome
The students will be able to map the conceptual database design to logical (relational)
database design.
Problem Statement
Map the ER/EER diagram of the COMPANY and SPORTS TEAM database created in the
previous experiment to Relational Database Schema. Follow the below mentioned steps to
successfully map ER/EER model to relational tables:
Background Study
o Include as foreign key in S the primary key of the relation T that represents the other
entity type participating in R.
Preparatory Questions
Q1) In which of the following, a separate schema is created consisting of that attribute and the
primary key of the entity set.
1) A many-to-many relationship set
2) A multivalued attribute of an entity set
3) A one-to-many relationship set
4) All of the mentioned
1) 2
2) 3
3) 4
4) 5
Q3) Consider the data given in above question. Which of the following is a correct attribute set
for one of the tables for the correct answer to the above question?
Q4) Let E1 and E2 be two entities in an E/R diagram with simple single-valued attributes. R1
and R2 are two relationships between E1 and E2, where R1 is one-to-many and R2 is many-to-
DBMS Lab Workbook (CSL214) | 16
2025-26
many. R1 and R2 do not have any attributes of their own. What is the minimum number of tables
required to represent this situation in the relational model?
1) 2
2) 3
3) 4
4) 5
Q5) What is the min and max number of tables required to convert an ER diagram with 2 entities
and 1 relationship between them with partial participation constraints of both entities?
Experiment No: 3
Student Name and Roll Number: Sara Sharma 24CSU184
Link to Code:
Date: 6/08/2025
Faculty Signature:
Marks:
Objective
To apply SQL integrity constraints as per the DDL statements given below for COMPANY
database.
Program Outcome
The students will understand how a database is created followed by insertion of relevant data.
The students will understand the need of applying various types of integrity constraints such
as primary key, foreign key, unique key, NOT NULL, default and CHECK etc
Problem Statement
DBMS Lab Workbook (CSL214) | 18
2025-26
DBMS Lab Workbook (CSL214) | 19
2025-26
1) Primary Key
2) Foreign Key
3) Unique
4) Default
5) Auto-increment
6) Check
7) Not Null
Background Study
1) Primary Key Constraint: A column or group of columns in a table which helps us to uniquely
identifies every row in that table is called a primary key. This DBMS can't be a duplicate.
The same value can't appear more than once in the table.
2) Foreign Key (Referential integrity constraint): This constraint identifies any column
referencing the PRIMARY KEY in another table. It establishes a relationship between two
columns in the same table or between different tables. For a column to be defined as a
Foreign Key, it should be a defined as a Primary Key in the table which it is referring. One
or more columns can be defined as Foreign key.
Syntax to define a Foreign key at column level:
[CONSTRAINT constraint_name] REFERENCES Referenced_Table_name(column_name)
DBMS Lab Workbook (CSL214) | 20
2025-26
3) SQL Not Null Constraint : This constraint ensures all rows in the table contain a definite
value for the column which is specified as not null. Which means a null value is not
allowed.
4) SQL Unique Key: This constraint ensures that a column or a group of columns in each row
have a distinct value. A column(s) can have a null value but the values cannot be
duplicated.
5) SQL Check Constraint : This constraint defines a business rule on a column. All the rows
must satisfy this rule. The constraint can be applied for a single column or a group of
columns.
Syntax to define a Check constraint:
[CONSTRAINT constraint_name] CHECK (condition)
DBMS Lab Workbook (CSL214) | 21
2025-26
Output: Screenshots
DBMS Lab Workbook (CSL214) | 22
2025-26
DBMS Lab Workbook (CSL214) | 23
2025-26
DBMS Lab Workbook (CSL214) | 24
2025-26
DBMS Lab Workbook (CSL214) | 25
2025-26
DBMS Lab Workbook (CSL214) | 26
2025-26
DBMS Lab Workbook (CSL214) | 27
2025-26
Preparatory Questions
1) Suppose (A, B) and (C,D) are two relation schemas. Let r1 and r2 be the corresponding
relation instances. B is a foreign key that refers to C in r2. If data in r1 and r2 satisfy
referential integrity constraints, which of the following is ALWAYS TRUE?
DBMS Lab Workbook (CSL214) | 28
2025-26
1) A
2) B
3) C
4) D
CREATE TABLE S (
a INTEGER,
d INTEGER,
e INTEGER,
PRIMARY KEY (d),
FOREIGN KEY (a) references R)
Q5) The following table has two attributes A and C where A is the primary key and C is the
foreign key referencing A with on-delete cascade.
A C
2 4
3 4
4 3
5 2
7 2
9 5
6 4
The set of all tuples that must be additionally deleted to preserve referential integrity when the
tuple (2,4) is deleted is:
Experiment No: 4
Student Name and Roll Number: Sara Sharma 24CSU184
Link to Code:
Date: 3/09/2025
Faculty Signature:
Marks:
DBMS Lab Workbook (CSL214) | 31
2025-26
Objective
Program Outcome
The students will be able to retrieve zero or more rows from one or more database tables or
database views.
Problem Statement
From the COMPANY database as mentioned and described in the previous database :
1) Retrieve the birth date and address of the employee(s) whose name
is ‘John B. Smith’.
2) Retrieve the name and address of all employees who work for the ‘Research’ department.
3) For every project located in ‘Stafford’, list the project number, the
controlling department number, and the department manager’s last name,
address, and birth date
4) Select all combinations of EMPLOYEE Ssn and DEPARTMENT Dname in the database.
5) Retrieve all the attribute values of any EMPLOYEE who works in DEPARTMENT
number 5.
6) Retrieve all distinct salary values.
7) Make a list of all project numbers for projects that involve an employee whose last name
is ‘Smith’, either as a worker or as a manager of the department that controls the project.
8) Retrieve all employees whose address is in Houston, Texas.
9) Find all employees who were born during the 1950s
10) Show the resulting salaries if every employee working on the ‘ProductX’ project is given
a 10 percent raise.
11) Retrieve a list of employees and the projects they are working on, ordered by department
and, within each department, ordered alphabetically by last name, then first name.
DBMS Lab Workbook (CSL214) | 32
2025-26
Background Study
1) Structured Query Language SQL contains statements for data definitions, queries, and
updates (both DDL and DML)
2) Domain
o Name used with the attribute specification
o Makes it easier to change the data type for a domain that is used by numerous
attributes
4) Out of the complete Database we create we can easily pick out and filter certain amount
of data by using the SQL queries as :
WHERE <condition>;
o <attribute list> is a list of attribute names whose values are to be retrieved by the
query.
o <table list> is a list of the relation names required to process the query.
o <condition> is a conditional (Boolean) expression that identifies the tuples to be
retrieved by the query.
5) Ambiguous Attribute Names: Same name can be used for two (or more) attributes as long
as the attributes are in different relations, these are made to differ by mentioning their
table names before the attribute names.
6) Aliasing, Renaming Tuple variables: We can rename the tables into some smaller easier
names as per choice when it has to be used multiple times in the query.
7) DISTINCT keyword is used when the query wishes to derive no two duplicate values.
8) SET operations such as UNION and INTERSECT can also be applied on the tables to
filter out the values as per choice.
DBMS Lab Workbook (CSL214) | 33
2025-26
9) Substring Pattern matching is carried out by the use of the keyword LIKE which helps in
retrieving the column values of the tuple matching our mentioned substring.
Output: Screenshots
DBMS Lab Workbook (CSL214) | 34
2025-26
DBMS Lab Workbook (CSL214) | 35
2025-26
DBMS Lab Workbook (CSL214) | 36
2025-26
DBMS Lab Workbook (CSL214) | 37
2025-26
DBMS Lab Workbook (CSL214) | 38
2025-26
DBMS Lab Workbook (CSL214) | 39
2025-26
DBMS Lab Workbook (CSL214) | 40
2025-26
DBMS Lab Workbook (CSL214) | 41
2025-26
DBMS Lab Workbook (CSL214) | 42
2025-26
DBMS Lab Workbook (CSL214) | 43
2025-26
DBMS Lab Workbook (CSL214) | 44
2025-26
DBMS Lab Workbook (CSL214) | 45
2025-26
DBMS Lab Workbook (CSL214) | 46
2025-26
Preparatory Questions
1) BETWEEN operator
2) LIKE operator
3) EXISTS operator
4) None of the above
Q2) In SQL which commands are used to change the storage characteristics of the table?
DBMS Lab Workbook (CSL214) | 47
2025-26
1) ALTER TABLE
2) MODIFY TABLE
3) CHANGE TABLE
4) All of the above
Q3) ___________removes all rows from a table without logging the individual row deletions.
1) DELETE
2) REMOVE
3) DROP
4) TRUNCATE
Q4) If you don’t specify ASC or DESC after a SQL ORDER BY clause, the following is used by
default :
1) ASC
2) DESC
3) There is no default value
4) None of the mentioned
Experiment No: 5
Student Name and Roll Number: Sara Sharma
Link to Code:
Date: 08/10/2025
Faculty Signature:
Marks:
Objective
Program Outcome
The students will be to establish a connection between two or more database tables based on
matching columns, thereby creating a relationship between the tables.
Problem Statement
Consider the Sample database given below and answer the queries as stated:
Pack_grades
Customers
Packages
Sectors
Sector_id Sector_name
1) Write a query to display first name, last name, package number and internet speed for all
customers.
2) Write a query to display first name, last name, package number and internet speed for all
customers whose package number equals 22 or 27. Order the query in ascending order by last
name.
3) Display the package number, internet speed, monthly payment and sector name for all
packages (Packages and Sectors tables).
4) Display the customer name, package number, internet speed, monthly payment and sector
name for all customers (Customers, Packages and Sectors tables).
5) Display the customer name, package number, internet speed, monthly payment and sector
name for all customers in the business sector (Customers, Packages and Sectors tables).
6) Display the last name, first name, join date, package number, internet speed and sector name
for all customers in the private sector who joined the company in the year 2006.
7) Display the package number, internet speed, monthly payment and package grade for all
packages (Packages and Pack_Grades tables).
8) Display the first name, last name, internet speed and monthly payment for all customers. Use
INNER JOIN to solve this exercise.
9) Display the last name, first name and package number for all customers who have the same
package number as customer named ‘Amado Taylor’ (Customers table).
10) Display the package number and internet speed for all packages whose internet speed is
equal to the internet speed of package number 10 (Packages table).
Background Study
DBMS Lab Workbook (CSL214) | 50
2025-26
1) JOINED TABLE: Permits users to specify a table resulting from a join operation in the
FROM clause of a query
o The attributes of such a table are all the attributes of the first table followed by all the
attributes of the second table.
o The default type of join in a joined table is called an inner join, where a tuple is included
in the result only if a matching tuple exists in the other relation.
o It is possible to rename the attributes so that they match, if the names of the join attributes
are not the same in the base relations.
Output: Screenshots
DBMS Lab Workbook (CSL214) | 52
2025-26
Preparatory Questions
SELECT Count(*)
FROM ( ( SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN ( SELECT Bank_Manager, Loan_Amount
FROM Loan_Records) AS T );
1) 3
2) 9
3) 5
4) 6
2) Cartesian
3) Both Equijoins and Cartesian
4) None of the mentioned
Q3) Which join refers to join records from the write table that have no matching key in the left
table are include in the result set:
1) Left outer join
2) Right outer join
3) Full outer join
4) Half outer join
Q5) Which view that contains more than one table in the top-level FROM clause of the SELECT
statement:
1) Join view
2) Datable join view
3) Updatable join view
4) All of the mentioned
DBMS Lab Workbook (CSL214) | 54
2025-26
Experiment No: 6
Student Name and Roll Number: Sara Sharma
Link to Code:
Date: 08/10/2025
Faculty Signature:
Marks:
Objective
Program Outcome
DBMS Lab Workbook (CSL214) | 55
2025-26
The students will understand the need of applying an aggregate function to get a single value
from a set of values, thus, expressing the significance of the data it is computed from.
Problem Statement
Consider the COMPANY database in Experiment 1 and execute the following queries:
1) Find the sum of the salaries of all employees, the maximum salary, the minimum salary,
and the average salary.
2) Find the sum of the salaries of all employees of the ‘Research’ department, as well as the
maximum salary, the minimum salary, and the average salary in this department.
3) Retrieve the total number of employees in the company.
4) Retrieve the number of employees in the ‘Research’ department.
5) Count the number of distinct salary values in the database
6) For each department, retrieve the department number, the number of employees in the
department, and their average salary.
7) For each project, retrieve the project number, the project name, and the number of
employees who work on that project.
8) For each project on which more than two employees work, retrieve the project number,
the project name, and the number of employees who work on the project
9) For each project, retrieve the project number, the project name, and the number of
employees from department 5 who work on the project.
10) For each department that has more than five employees, retrieve the department
number and the number of its employees who are making more than $40,000.
Background Study
1) Aggregate Functions: Used to summarize information from multiple tuples into a single-
tuple summary
3) Built-in aggregate functions: COUNT, SUM, MAX, MIN, and AVG (NULL values
discarded when aggregate functions are applied to a particular column)
7) If NULLs exist in grouping attribute, then separate group created for all tuples with a
NULL value in grouping attribute
9) SELECT clause includes only the grouping attribute and the aggregate functions to be
applied on each group of tuples.
10) WHERE clause limit the tuples to which functions are applied, the HAVING clause
serves to choose whole groups
Output: Screenshots
DBMS Lab Workbook (CSL214) | 57
2025-26
DBMS Lab Workbook (CSL214) | 58
2025-26
DBMS Lab Workbook (CSL214) | 59
2025-26
DBMS Lab Workbook (CSL214) | 60
2025-26
Preparatory Questions
Q1) Which of the following statements are TRUE about an SQL query? P: An SQL query can
contain a HAVING clause even if it does not have a GROUP BY clause Q : An SQL query can
contain a HAVING clause only if it has a GROUP BY clause R : All attributes used in the
GROUP BY clause must appear in the SELECT clause S : Not all attributes used in the GROUP
BY clause need to appear in the SELECT clause
1) P and R
2) P and S
3) Q and R
4) Q and S
Q2) Consider a database table T containing two columns X and Y each of type integer. After the
creation of the table, one record (X=1, Y=1) is inserted in the table. Let MX and My denote the
respective maximum values of X and Y among all records in the table at any point in time. Using
MX and MY, new records are inserted in the table 128 times with X and Y values being MX+1,
2*MY+1 respectively. It may be noted that each time after the insertion, values of MX and MY
change. What will be the output of the following SQL query after the steps mentioned above are
carried out?
1) the average salary is more than the average salary in the company
2) the average salary of male employees is more than the average salary of all
male employees in the company
3) the average salary of male employees is more than the average salary of
employees in the same department
4) the average salary of male employees is more than the average salary in the
company
Q5) Observe the given SQL query and choose the correct option.
Experiment No: 7
Student Name and Roll Number: Sara Sharma
Link to Code:
Date: 08/10/2025
Faculty Signature:
Marks:
Objective
Program Outcome
The students will understand how to devise independent and correlated nested queries.
DBMS Lab Workbook (CSL214) | 63
2025-26
Problem Statement
Consider the COMPANY database in Experiment 1 and execute the following queries:
1) Make a list of all project numbers for projects that involve an employee whose last name is
‘Smith’, either as a worker or as a manager of the department that controls the project.
2) Select the Essns of all employees who work on the same project and hours as some project
that employee ‘John Smith’ (whose Ssn = ‘123456789’) works on.
3) Return the names of employees whose salary is greater than the salary of all the employees in
department 5
4) Retrieve the name of each employee who has a dependent with the same first name and is the
same sex as the employee
5) Retrieve the names of employees who have no dependents
6) List the names of managers who have at least one dependent using EXISTS and NOT
EXISTS functions
7) Retrieve the name of each employee who works on all the projects controlled by department
number 5 using EXISTS and NOT EXISTS functions
8) Retrieve the names of all employees who have two or more dependents
9) Retrieves the names of all employees who work on only one project
Background Study
1) SQL allows queries that check whether an attribute value is NULL: IS or IS NOT NULL
2) Nested Queries: Complete select-from-where blocks within WHERE clause of another query
o Nested Queries generally return a table (relation)
4) = ANY (or = SOME) Operator: Returns TRUE if the value v is equal to some value in the set
V (equivalent to IN)
5) ALL Operator: (v > ALL V) returns TRUE if the value v is greater than all the values in the
set (or multiset) V.
o Other operators that can be combined with ANY (or SOME) and ALL: >, >=, <, <=,
and <>
DBMS Lab Workbook (CSL214) | 64
2025-26
6) Possible ambiguity among attribute names if attributes of the same name exist—one in a
relation in the FROM clause of the outer query, and another in a relation in the FROM clause
of the nested query.
o Thumb Rule: reference to an unqualified attribute refers to the relation declared in the
innermost nested query.
7) Whenever a condition in the WHERE clause of a nested query references some attribute of a
relation declared in the outer query, the two queries are said to be correlated.
o In a correlated query, the nested query is evaluated once for each tuple (or
combination of tuples) in the outer query
8) EXISTS function: Check whether the result of a correlated nested query is empty or not.
9) EXISTS and NOT EXISTS are typically used in conjunction with a correlated nested query.
10) EXISTS(Q): returns TRUE if there is at least one tuple in the result of the nested query Q,
and it returns FALSE otherwise.
11) NOT EXISTS(Q): returns TRUE if there are no tuples in the result of nested query Q, and it
returns FALSE otherwise.
Output: Screenshots
DBMS Lab Workbook (CSL214) | 65
2025-26
DBMS Lab Workbook (CSL214) | 66
2025-26
DBMS Lab Workbook (CSL214) | 67
2025-26
DBMS Lab Workbook (CSL214) | 68
2025-26
DBMS Lab Workbook (CSL214) | 69
2025-26
DBMS Lab Workbook (CSL214) | 70
2025-26
DBMS Lab Workbook (CSL214) | 71
2025-26
Preparatory Questions
SELECT Count(*)
FROM ( ( SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN ( SELECT Bank_Manager, Loan_Amount
FROM Loan_Records) AS T );
1) 3
2) 9
3) 5
4) 6
Q2) A relational schema for a train reservation database is given below. Passenger (pid, pname,
age) Reservation (pid, class, tid)
Table: Passenger
pid pname age
-----------------
0 Sachin 65
1 Rahul 66
2 Sourav 67
3 Anil 69
Table : Reservation
pid class tid
---------------
0 AC 8200
1 AC 8201
DBMS Lab Workbook (CSL214) | 72
2025-26
2 SC 8201
5 AC 8203
1 SC 8204
3 AC 8202
What pids are returned by the following SQL query for the above instance of the tables?
SELECT pid
FROM Reservation ,
WHERE class ‘AC’ AND
EXISTS (SELECT *
FROM Passenger
WHERE age > 65 AND
Passenger. pid = [Link])
1) 1,0
2) 1,2
3) 1,3
4) 1,5
Assume that relations corresponding to the above schema are not empty. Which one of the
following is the correct interpretation of the above query?
1) Find the names of all suppliers who have supplied a non-blue part.
2) Find the names of all suppliers who have not supplied a non-blue part.
3) Find the names of all suppliers who have supplied only blue parts.
4) Find the names of all suppliers who have not supplied only blue parts.
5) None
Q4) Consider the table employee(empId, name, department, salary) and the two queries Q1 ,Q2
below. Assuming that department 5 has more than one employee, and we want to find the
employees who get higher salary than anyone in the department 5, which one of the statements is
TRUE for any arbitrary employee table?
salesRepId is a foreign key referring to empId of the employee relation. Assume that each
employee makes a sale to at least one customer. What does the following query return?
SELECT empName
FROM employee E
WHERE NOT EXISTS ( SELECT custId
FROM customer C
WHERE [Link] = [Link]
AND [Link] <> `GOOD`);
1) Names of all the employees with at least one of their customers having a ‘GOOD’ rating.
2) Names of all the employees with at most one of their customers having a ‘GOOD’ rating.
3) Names of all the employees with none of their customers having a ‘GOOD’ rating.
4) Names of all the employees with all their customers having a ‘GOOD’ rating.
DBMS Lab Workbook (CSL214) | 75
2025-26
Experiment 8
Student Name and Roll Number:
Semester /Section:
Link to Code:
Date:
Faculty Signature:
Marks:
Objective
Identifying contrast between Relational Databases and NoSQL, thereby recognizing their
applications.
Program Outcome
The students will install MongoDB shell and familiarize themselves with it.
Problem Statement
Background Study
MongoDB is a Schema less database. A database in MongoDB contains collections and inside
collections we have documents.
Database is a physical container for collections. A single MongoDB server typically has
multiple databases.
Collection is a group of MongoDB documents.
DBMS Lab Workbook (CSL214) | 76
2025-26
Documents within a collection can have different fields. A document is a set of key-value
pairs and have dynamic schema. Dynamic schema means that documents in the same
collection do not need to have the same set of fields or structure, and common fields in a
collection's documents may hold different types of data.
DBMS Lab Workbook (CSL214) | 77
2025-26
RDBMS MongoDB
Output: Screenshots
DBMS Lab Workbook (CSL214) | 78
2025-26
Preparatory Questions
1) tables
2) collections
3) rows
4) all the mentioned
DBMS Lab Workbook (CSL214) | 79
2025-26
1) JSON
2) XML
3) JScript
4) All of the mentioned
1) 2 MB
2) 16 MB
3) 12 MB
4) There is no maximum size. It depends on RAM
Experiment 9
Student Name and Roll Number:
Semester /Section:
Link to Code:
Date:
Faculty Signature:
Marks:
DBMS Lab Workbook (CSL214) | 80
2025-26
Objective
Program Outcome
Problem Statement
4) Retrieve the details of all projects that are being run in department number 50.
5) Retrieve the details of the first project that is being run in department number 50 in
formatted manner.
6) Return the formatted/structured project details of all projects in department number “5”
and project name as “ProductZ”.
7) Return the project details (including project name, project number and department
number and excluding project location and default primary key) of all projects with
department number “5” or project name as “ProductZ”.
8) Return the formatted/structured project details of all projects with department number
less than “10” and project name as “ProductZ” or project location as “Delhi”.
Background Study
1) use: This command is used to create a database in MongoDB. It will return an existing
database or will create a new database if it dosen’t exist.
DBMS Lab Workbook (CSL214) | 81
2025-26
Output: Screenshots
DBMS Lab Workbook (CSL214) | 82
2025-26
Preparatory Questions
1) find
2) move
3) shell
4) replace
Q2) When you query a collection, MongoDB returns a ________ object that contains the results
of the query.
DBMS Lab Workbook (CSL214) | 83
2025-26
1) row
2) cursor
3) colums
4) none of the mentioned
Q3) Which of the following method is called while accessing documents using the array index
notation ?
1) [Link]()
2) [Link]()
3) [Link]()
4) all of the mentioned
Q4) The mongo shell and the drivers provide several cursor methods that call on the cursor
returned by the _______ method to modify its behavior.
1) cursor()
2) find()
3) findc()
4) none of the mentioned
1) sort()
2) order()
3) orderby()
4) all of the mentioned
Experiment 10
Student Name and Roll Number:
Semester /Section:
Link to Code:
Date:
Faculty Signature:
DBMS Lab Workbook (CSL214) | 84
2025-26
Marks:
Objective
Program Outcome
The students will be able to perform advanced CRUD operations in MongoDB.
Problem Statement
Project
Possible Fields:
Project Name (Pname)
Project Number (Pnumber)
Department Number in which project is being run (Dnum)
Project Locations (Plocation)
Plocation can be an array of multiple locations (or)
Plocation can be a composite field with sub-fields – city, state, country
Department
Possible Fields:
Department Number (Dno)
Department Name (Dname)
Department Manager (Dmanager)
1) Insert multiple documents (2-3) together in the Project collection with atleast 1 project
location as a composite attribute
3) Write a MongoDB query to update the project location of all projects to “Pune” and
department number to “20” with project name “ProjectX”.
4) Write a MongoDB query to delete all the documents of collection “Project” with
department number “4”.
5) Write a MongoDB query to retrieve the project details of all projects with project location
as “Delhi” and “Mumbai” both assuming the following documents exist.
7) Write a MongoDB query to retrieve the project details project name, department
number, department name and department manager of projects with department manager
(for department in which the project is being run) as “ABC”.
Background Study
1) pretty() is used to display the query obtained in a neat manner with all the fields clearly
depicted one below the other.
2) Data for a particular field can also be stored as an array with multiple values for the field.
3) $all is used to match the array items for the particular field.
DBMS Lab Workbook (CSL214) | 86
2025-26
o [Link]({Plocation:{$all:["Delhi","Mumbai"]}}).pretty()
4) $elemMatch: This operator matches documents that contain an array field with at least
one element that matches all the specified query criteria.
o Syntax: { <field>: { $elemMatch: { <query1>, <query2>, ... } } }
5) Fields can be embedded in the field too and while using find in such a case, always refer
the field embedded in another field by using a dot notation and in quotes.
6) AND/OR Operations
>[Link]
>db.collection_name.find({$and: ({$and:[{Dnum:5},
AND
[{key1: value1}, {key2:value2}]}) {Pname:"ProductZ“}]}).pretty
();
>[Link]
>db.collection_name.find({$or: ({$or:[{Dnum:5},
OR
[{key1: value1}, {key2:value2}]}) {Pname:"ProductZ“}]}).pretty
();
7) Documents can either be embedded in one to one relation or one to many relation
o In one to one, the new field contains only a single embedded document.
o In one to many, the new field contains an array of multiple embedded documents.
Output: Screenshots
DBMS Lab Workbook (CSL214) | 87
2025-26
Preparatory Questions
Q1) The order of documents returned by a query is not defined unless you specify a ______
1) sortfind()
2) sortelse()
DBMS Lab Workbook (CSL214) | 88
2025-26
3) sort()
4) none of the mentioned
Q2) In aggregation pipeline, the _______ pipeline stage provides access to MongoDB queries.
1) $catch
2) $match
3) $batch
4) All of the mentioned
Q4) Which of the following query selects documents in the records collection that match the
condition { “user_id”: { $lt: 42 } }?
1) [Link]( { “user_id”: { $lt: 42 } }, { “history”: 0 } )
2) [Link]( { “user_id”: { $lt: 42 } }, { “history”: 0 } )
3) [Link]( { “user_id”: { $lt: 42 } }, { “history”: 1 } )
4) [Link]( { “user_id”: { $lt: 42 } }, { “history”: 0 } )
Semester /Section:
DBMS Lab Workbook (CSL214) | 89
2025-26
Link to Code:
Date:
Faculty Signature:
Marks:
Objective
Design an ER/ EER Diagram, relational schema and implement the database in MongoDB.
Program Outcome
The students will design and implement DBMS concepts on a real-world project.
Problem Statement
The NorthCap University has recently launched new specializations in B-Tech (Computer
Science & Engineering). To facilitate this, a new admission application needs to be developed,
where an Admin should be able to create a new application, update an existing application and
delete any application. The application should contain the below mentioned fields:
1) Student Name
2) Student Id
3) Father’s Name
4) Mother’s Name
5) Gender
6) DOB
7) Nationality
8) Address
9) Marks in Class X. XII and JEE.
10) Email
11) Contact No.
12) B-Tech CSE Specialization Choice 1 (IOT, Data Science, Cyber Security, Full Stack and
Game
DBMS Lab Workbook (CSL214) | 90
2025-26
Tech)
13) B-Tech CSE Specialization Choice 2 (IOT, Data Science, Cyber Security, Full Stack and
Game
Tech)
Based on the application requirements and your specific assumptions, draw an ER/EER model
for the application’s database and further map it to appropriate relational schema.
Collections
1. Student
Possible Fields:
Student Name (Sname)
Student Id should be unique (Sid)
Address
Address can be an array of multiple address(or)
Address can be a composite field with sub field-city, state, country
Marks in JEE. (Marks_JEE)
B-Tech CSE Specialization Choice 1 (Choise_1)
B-Tech CSE Specialization Choice 2 (Choise_2)
2. Specialization
Possible Fields:
B-Tech CSE Specialization Choice IOT (IOT)
B-Tech CSE Specialization Data Science (Data_Science)
B-Tech CSE Specialization Cyber Security (Cyber_Security)
B-Tech CSE Specialization Full Stack (Full_Stack)
B-Tech CSE Specialization Game Tech (Game_Tech)
Queries:
1. Insert multiple documents (2-3) together in the Student collection with at least 1 student
Address as a composite attribute.
3. Write a MongoDB query to return the formatted/structured Student details of all Students
with Specialization choice 1 “IOT” and Student name as “RAM”.
4. Write a MongoDB query to return the formatted/structured Student details (including Student
name, choice1 and choice2 and excluding other fields) of all students with choice1 as “IOT”
or Student name as “RAM”.
5. Write a MongoDB query to return the formatted/structured Student details of all students
with choice1 equal to “Full_Stack” and Student JEE Marks less than 200 or student address
as “Delhi”.
6. Write a MongoDB query to update the student choice1 to “IOT” and JEE Marks to “80” with
student name “XYZ”.
7. Write a MongoDB query to delete all the documents of collection “student” with choice1 as
“IOT”.
8. Write a MongoDB query to retrieve the Student details of all students with address as
“Delhi” and “Mumbai”.
9. Write a MongoDB query creating a One to Many Relation between a document of“student”
Collection and “Specialization” Collection.
10. Write a MongoDB query to retrieve the student details student name, Marks_JEE, of
student with specialization as Cyber_Security (for department in which the project is being
run) as “ABC”.
DBMS Lab Workbook (CSL214) | 92
2025-26
Output: Screenshots