0% found this document useful (0 votes)
16 views92 pages

DBMS Lab Workbook

The document is a lab workbook for a Database Management System course (CSL 214) at The NorthCap University, detailing various experiments related to database design and SQL operations. It includes objectives, problem statements, and preparatory questions for each experiment, focusing on ER/EER diagrams, relational database schema design, SQL integrity constraints, and NoSQL databases. The workbook is structured for students to document their progress and understanding throughout the lab sessions in the 2025-26 academic session.

Uploaded by

sharmasara774
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views92 pages

DBMS Lab Workbook

The document is a lab workbook for a Database Management System course (CSL 214) at The NorthCap University, detailing various experiments related to database design and SQL operations. It includes objectives, problem statements, and preparatory questions for each experiment, focusing on ER/EER diagrams, relational database schema design, SQL integrity constraints, and NoSQL databases. The workbook is structured for students to document their progress and understanding throughout the lab sessions in the 2025-26 academic session.

Uploaded by

sharmasara774
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Database Management System

(CSL 214)

Lab Workbook

Faculty Name: Ms. Kanika Gupta Student Name:

Roll No.:

Semester: III

Group:

Department of Computer Science and Engineering

The NorthCap University, Gurugram- 122017, India

Session 2025-26
DBMS Lab Workbook (CSL214) | 2
2025-26

INDEX

Date of Date of Sign CO Sign


[Link] Experiment Title
Experiment Submission Student Covered Faculty
Design an ER/EER diagram for the
1 COMPANY and SPORTS TEAM CO2
database.
Design a Relational Database
Schema for the COMPANY and
2 SPORTS TEAM database from the CO2
ER/EER diagram.

To apply SQL integrity constraints


3 as per the DDL statements given CO4
below for COMPANY database.

To familiarize with SELECT-


FROM-WHERE SQL simple
4 queries on the COMPANY CO4
database.

To familiarize with JOIN


5 operations in SQL on the CO4
COMPANY database.

To understand Aggregate functions


6 using SQL queries on the CO4
COMPANY database.

To familiarize with nested SQL


7 queries on the COMPANY CO4
database.

Identifying contrast between


Relational Databases and NoSQL,
8 thereby recognizing their CO5
applications.

Create COMPANY database using


9 NoSQL database - MongoDB. CO5

Retrieve data from NoSQL


10 database - MongoDB. CO5
DBMS Lab Workbook (CSL214) | 3
2025-26

VA - Design an ER/ EER


Diagram, relational schema and CO2,
11 implement the database in -8-
CO5
MongoDB.

Experiment No: 1
Student Name and Roll Number: Sara Sharma 24CSU184
DBMS Lab Workbook (CSL214) | 4
2025-26

Semester /Section: 3rd -AB

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.

 A department controls several projects, each of which has a unique


name, a unique number, and a single location.
 The company is organized into departments. Each department has a unique
name, a unique number, and a particular employee who manages the
department. We keep track of the start date when that employee began managing the
department. A department may have several locations.
 We store each employee’s name, Social Security number, address, salary, sex
(gender), and birth date. An employee is assigned to one department, but
may work on several projects, which are not necessarily controlled by the
DBMS Lab Workbook (CSL214) | 5
2025-26

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:

i) Entities (Strong and Weak)


ii) Relationships
iii) Participation constraints
iv) Various types of attributes
v) Recursive relations
vi) Mapping cardinalities
vii) Binary/Ternary relationship
viii) Specialization/Generalization etc.

Background Study

ER Diagram Symbols and Notations:

1) Entity:
o Real-world object distinguishable from other objects.
o An entity is described using a set of attributes.

2) Entity Set: A collection of similar entities. Eg: all employees.

o All entities in an entity set have the same set of attributes.

o Each entity set has a key.

o Each attribute has a domain.


DBMS Lab Workbook (CSL214) | 6
2025-26

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?

1) An attribute of an entity can have more than one value


2) An attribute of an entity can be composite
3) In a row of a relational table, an attribute can have more than one value
4) In a row of a relational table, an attribute can have exactly one value or a NULL value

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

Semester /Section: 3rd -AB

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:

Step 1: Mapping of Regular Entity Types

Step 2: Mapping of Weak Entity Types

Step 3: Mapping of Binary 1:1 Relation Types

Step 4: Mapping of Binary 1:N Relationship Types


DBMS Lab Workbook (CSL214) | 12
2025-26

Step 5: Mapping of Binary M:N Relationship Types

Step 6: Mapping of Multivalued attributes

Step 7: Mapping of N-ary Relationship Types

Step 8: Mapping EER Model Constructs to Relations

Step 9: Options for Mapping Specialization or Generalization

Step 10: Mapping of Union Types (Categories)

Background Study

1) Mapping of Regular Entity Types


o For each regular (strong) entity type E in the ER schema, create a relation R that includes
all the simple attributes of E. Choose one of the key attributes of E as the primary key for
R. If the chosen key of E is composite, the set of simple attributes that form it will
together form the primary key of R.

2) Mapping of Weak Entity Types


o For each weak entity type W in the ER schema with owner entity type E, create a
relation R and include all simple attributes (or simple components of composite
attributes) of W as attributes of R.
o Include as foreign key attributes of R the primary key attribute(s) of the relation(s) that
correspond to the owner entity type(s).

3) Mapping of Binary 1:1 Relationship Types


o For each binary 1:1 relationship type R in the ER schema, identify the relations S and T
that correspond to the entity types participating in R. This has 3 approaches :
 Foreign Key Approach
 Merged Relation Option
 Cross-reference or Relationship Relation Option

4) Mapping of Binary 1:N Relationship Types


o For each regular binary 1:N relationship type R, identify the relation S that represent the
participating entity type at the N-side of the relationship type.
DBMS Lab Workbook (CSL214) | 13
2025-26

o Include as foreign key in S the primary key of the relation T that represents the other
entity type participating in R.

5) Mapping of Binary M:N Relationship Types


o For each regular binary M:N relationship type R, create a new relation S to represent R.
o Include as foreign key attributes in S the primary keys of the relations that represent the
participating entity types; their combination will form the primary key of S.

6) Mapping of Multi-valued attributes


o For each multi-valued attribute, A, create a new relation R. This relation R will include an
attribute corresponding to A, plus the primary key attribute K-as a foreign key in R-of
the relation that represents the entity type of relationship type that has A as an attribute.

7) Mapping of N-ary Relationship Types


o For each n-ary relationship type R, where n>2, create a new relationship S to represent R.
o Include as foreign key attributes in S the primary keys of the relations that represent the
participating entity types.

8) Options for Mapping Specialization or Generalization


o Convert each specialization with m subclasses {S 1, S2,….,Sm} and generalized superclass
C, where the attributes of C are {k,a 1,…an} and k is the (primary) key, into relational
schemas using 1 of the following :
1) Multiple relations-Superclass and subclasses.
2) Multiple relations-Subclass relations only :
3) Single relation with one type attribute
4) Single relation with multiple type attributes.

9) Mapping of Union Types (Categories)


o For mapping a category whose defining superclass have different keys, it is customary to
specify a new key attribute, called a surrogate key, when creating a relation to
correspond to the category.
DBMS Lab Workbook (CSL214) | 14
2025-26

Relational Database Design


DBMS Lab Workbook (CSL214) | 15
2025-26

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

Q2) Consider the following ER diagram

The minimum number of tables needed to represent M, N, P, R1, R2 is

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?

1) {M1, M2, M3, P1}


2) {M1, P1, N1, N2}
3) {M1, P1, N1}
4) {M1, P1}

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?

1) Min 1 and max 2


2) Min 1 and max 3
3) Min 2 and max 3
4) Min 2 and max 2
DBMS Lab Workbook (CSL214) | 17
2025-26

Experiment No: 3
Student Name and Roll Number: Sara Sharma 24CSU184

Semester /Section: 3rd -AB

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

Implement the following types of integrity constraints:

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.

Syntax to define a Primary key at column level:


column name datatype [CONSTRAINT constraint_name] PRIMARY KEY

Syntax to define a Primary key at table level:


[CONSTRAINT constraint_name] PRIMARY KEY (column_name1,column_name2,..)

Rules for defining Primary key:

o Two rows can't have the same primary key value


o It must for every row to have a primary key value.
o The primary key field cannot be null.
o The value in a primary key column can never be modified or updated if any
foreign key refers to that primary key.

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

Syntax to define a Foreign key at table level:


[CONSTRAINT constraint_name] FOREIGN KEY(column_name) REFERENCES
referenced_table_name(column_name);

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.

Syntax to define a Not Null constraint:


[CONSTRAINT constraint name] NOT NULL

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.

Syntax to define a Unique key at column level:


[CONSTRAINT constraint_name] UNIQUE

Syntax to define a Unique key at table level:


[CONSTRAINT constraint_name] UNIQUE(column_name)

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

2) Given the following statements:


S1: A foreign key declaration can always be replaced by an equivalent check assertion in
SQL.
S2: Given the table R(a,b,c) where a and b together form the primary key, the following is a
valid table definition.

CREATE TABLE S (
a INTEGER,
d INTEGER,
e INTEGER,
PRIMARY KEY (d),
FOREIGN KEY (a) references R)

Which one of the following statements is CORRECT?


1) S1 is TRUE and S2 is FALSE.
2) Both S1 and S2 are TRUE.
3) S1 is FALSE and S2 is TRUE.
4) Both S1 and S2 are FALSE

Q3) Which of the following is not an integrity constraint?


1) Not null
2) Positive
3) Unique
4) Check ‘predicate’
DBMS Lab Workbook (CSL214) | 29
2025-26

Q4) CREATE TABLE Manager(ID NUMERIC,Name VARCHAR(20),budget NUMERIC,Details


VARCHAR(30));
In order to ensure that the value of budget is non-negative which of the following should be
used?
1)Check(budget>0)
2)Check(budget<0)
3)Alter(budget>0)
4) Alter(budget<0)

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:

1) (3,4) and (6,4)


2) (5,2) and (7,2)
3) (5,2), (7,2) and (9,5)
4) (3,4), (4,3) and (6,4)
DBMS Lab Workbook (CSL214) | 30
2025-26

Experiment No: 4
Student Name and Roll Number: Sara Sharma 24CSU184

Semester /Section: 3rd -AB

Link to Code:

Date: 3/09/2025
Faculty Signature:

Marks:
DBMS Lab Workbook (CSL214) | 31
2025-26

Objective

To familiarize with SELECT-FROM-WHERE SQL simple queries on the COMPANY database.

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

3) Inserting values in our table using the commands :


INSERT INTO EMPLOYEE (Fname, Lname, Dno, Ssn)

VALUES (‘Richard’, ‘Marini’, 4, ‘653298653’)

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 :

SELECT <attribute list>

FROM <table list>

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.

10) ORDERBY <attributes>


o Helps in sorting the tuple values of the attributes by default set to ascending and can
be changed to descending .

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

Q1) Which operator performs Pattern matching ?

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

Q5) What is the purpose of the SQL AS clause?


1) The AS SQL clause is used to change the name of a column in the result set or to assign a
name to a derived column
2) The AS clause is used with the JOIN clause only
3) The AS clause defines a search condition
4) All of the mentioned
DBMS Lab Workbook (CSL214) | 48
2025-26

Experiment No: 5
Student Name and Roll Number: Sara Sharma

Semester /Section: 3rd -AB

Link to Code:

Date: 08/10/2025
Faculty Signature:

Marks:

Objective

To familiarize with JOIN operations in SQL on the COMPANY database.

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

Grade_id Grade_name Min_price Max_price


DBMS Lab Workbook (CSL214) | 49
2025-26

Customers

Customer_i First_name Last_name Birth_date Join_date City Pack_id State


d

Packages

Pack_id Speed Start_date Monthly_payment Sector_id

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.

2) NATURAL JOIN on two relations R and S


o No join condition specified.
o Implicit EQUIJOIN condition for each pair of attributes with same name from R & S

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.

3) LEFT OUTER JOIN


o Every tuple in left table must appear in result
o If no matching tuple, padded with NULL values for attributes of right table

4) RIGHT OUTER JOIN


o Every tuple in right table must appear in result
o If no matching tuple, padded with NULL values for the attributes of left table

5) FULL OUTER JOIN


o Used when both the tables are taken completely

6) CROSS JOIN – for Cartesian Product


DBMS Lab Workbook (CSL214) | 51
2025-26

Output: Screenshots
DBMS Lab Workbook (CSL214) | 52
2025-26

Preparatory Questions

Q1) Database table by name Loan_Records is given below.

Borrower Bank_Manager Loan_Amount


Ramesh Sunderajan 10000.00
Suresh Ramgopal 5000.00
Mahesh Sunderajan 7000.00

What is the output of the following SQL query?

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) Which product is returned in a join query have no join condition:


1) Equijoins
DBMS Lab Workbook (CSL214) | 53
2025-26

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

Q4) Which operation are allowed in a join view:


1) UPDATE
2) INSERT
3) DELETE
4) All of the mentioned

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

Semester /Section: 3rd -AB

Link to Code:

Date: 08/10/2025
Faculty Signature:

Marks:

Objective

To understand Aggregate functions using SQL queries on the COMPANY database.

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

2) Grouping: Create subgroups of tuples before summarizing

3) Built-in aggregate functions: COUNT, SUM, MAX, MIN, and AVG (NULL values
discarded when aggregate functions are applied to a particular column)

4) Functions can be used in the SELECT clause or in a HAVING clause

5) Partition relation into subsets of tuples


o Based on grouping attribute(s)
DBMS Lab Workbook (CSL214) | 56
2025-26

o Apply function to each such group independently

6) GROUP BY clause: Specifies grouping attributes

7) If NULLs exist in grouping attribute, then separate group created for all tuples with a
NULL value in grouping attribute

8) HAVING clause provides a condition on the summary information

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?

SELECT Y FROM T WHERE X=7;


1) 127
2) 255
3) 129
4) 257
DBMS Lab Workbook (CSL214) | 61
2025-26

Q3) The employee information in a company is stored in the relation

Employee (name, sex, salary, deptName)

Consider the following SQL query


select deptName
from Employee
where sex = 'M'
group by deptName
having avg (salary) > (select avg (salary) from Employee)
It returns the names of the department in which

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

Q4) Which of the following is aggregate function in SQL?


1) Avg
2) Select
3) Ordered by
4) distinct

Q5) Observe the given SQL query and choose the correct option.

SELECT branch_name, COUNT (DISTINCT customer_name)


FROM depositor, account
WHERE depositor.account_number = account.account_number
GROUP BY branch_id
1) The query is syntactically correct but gives the wrong answer
2) The query is syntactically wrong
3) The query is syntactically correct and gives the correct answer
DBMS Lab Workbook (CSL214) | 62
2025-26

4) The query contains one or more wrongly named clauses.

Experiment No: 7
Student Name and Roll Number: Sara Sharma

Semester /Section: 3rd -AB

Link to Code:

Date: 08/10/2025
Faculty Signature:

Marks:

Objective

To familiarize with nested SQL queries on the COMPANY database.

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)

3) Comparison Operator IN:


o Compares value v with a set (or multiset) of values V
o Evaluates to TRUE if v is one of the elements in V

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

Q1) Database table by name Loan_Records is given below.

Borrower Bank_Manager Loan_Amount


Ramesh Sunderajan 10000.00
Suresh Ramgopal 5000.00
Mahesh Sunderajan 7000.00

What is the output of the following SQL query?

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

Q3) Consider the following relational schema:

Suppliers(sid:integer, sname:string, city:string, street:string)


Parts(pid:integer, pname:string, color:string)
Catalog(sid:integer, pid:integer, cost:real)

Consider the following relational query on the above database:


SELECT [Link]
FROM Suppliers S
WHERE [Link] NOT IN (SELECT [Link]
FROM Catalog C
WHERE [Link] NOT IN (SELECT [Link]
FROM Parts P
WHERE [Link]<> 'blue'))
DBMS Lab Workbook (CSL214) | 73
2025-26

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?

Query1: Select [Link]


From employee e
Where not exists
(Select * From employee s where [Link] = “5” and [Link] >=[Link])

Query2: Select [Link]


From employee e
Where [Link] > Any
(Select distinct salary From employee s Where [Link] = “5”)
1) Q1 is the correct query
2) Q2 is the correct query
3) Both Q1 and Q2 produce the same answer.
4) Neither Q1 nor Q2 is the correct query
DBMS Lab Workbook (CSL214) | 74
2025-26

Q5) Consider the following relational schema:

employee(empId, empName, empDept)


customer(custId, custName, salesRepId, rating)

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

MongoDB installation and shell familiarity.

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

Relational database Non-relational and document-oriented


database
Need to design your tables, data structure, You can start coding without worrying
relations first. about tables and modify your objects at
a lesser cost of development.

Supports SQL query language Supports JSON query language


Table based Collection based and key-value pair
Row based Document based
Column based Field based
Each row will have same number of Each document can have different
columns number of fields
Primary Key Primary Key (Default key _id provided
by MongoDB itself)
Contains schema which is predefined Contains dynamic schema

Output: Screenshots
DBMS Lab Workbook (CSL214) | 78
2025-26

Preparatory Questions

Q1) Point out the correct statement:

1) A database is a set of key-value pairs


2) A MongoDB deployment hosts a number of databases
3) A document holds a set of collections
4) All of the mentioned

Q2) MongoDB stores all documents in:

1) tables
2) collections
3) rows
4) all the mentioned
DBMS Lab Workbook (CSL214) | 79
2025-26

Q3) BSON is a binary representation of ________ documents,

1) JSON
2) XML
3) JScript
4) All of the mentioned

Q4) The maximum size of a MongoDB document is

1) 2 MB
2) 16 MB
3) 12 MB
4) There is no maximum size. It depends on RAM

Q5) Which of the following statements is true?

1) MongoDB cannot be used as a file system.


2) MongoDB can run over single servers only.
3) Embedded documents and arrays reduce need for joins.
4) None

Experiment 9
Student Name and Roll Number:

Semester /Section:

Link to Code:

Date:
Faculty Signature:

Marks:
DBMS Lab Workbook (CSL214) | 80
2025-26

Objective

Create COMPANY database using NoSQL database - MongoDB.

Program Outcome

 The students will be able to perform basic CRUD operations in MongoDB.

Problem Statement

1) Create a COMPANY database with the following collections:


 Employee with fields Emp ID, Ename, Age, Mobile, Email, Address, Dno
 Department with fields Dnumber, Dname, Dlocation
 Project with fields Pname, Pnumber, Plocation, ControlDept

2) Insert 5 documents in each collection using different versions of “Insert” command.

3) Select all documents in a collection.

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

2) createCollection( ): To create a collections in a database

3) MongoDB provides the following methods to insert documents into a collection:

4) [Link](): used to insert one or multiple documents. To insert multiple


documents in a single query, pass an array of documents in insert() command.

5) [Link](): used to insert only one document.

6) [Link](): used to insert multiple documents. To insert multiple


documents in a single query, pass an array of documents in insert() command.

7) [Link](): this method is provided in MongoDB to read documents from a


collection. It returns a cursor to the matching documents. [Link](<query
filter>, <projection>) accepts second optional parameter that is list of fields that you want
to retrieve in the form { field1: <value>, field2: <value> ... }.

8) [Link](): it returns the first occurrence of document, otherwise null.

Output: Screenshots
DBMS Lab Workbook (CSL214) | 82
2025-26

Preparatory Questions

Q1) Which of the following method is used to query documents in collections?

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

Q5) Which of the following method corresponds to Order by clause in SQL?

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

Retrieve data from NoSQL database - MongoDB.

Program Outcome
 The students will be able to perform advanced CRUD operations in MongoDB.

Problem Statement

Create a database with the following collections:

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)

Execute the following queries:

1) Insert multiple documents (2-3) together in the Project collection with atleast 1 project
location as a composite attribute

2) Write the “Select * from Project” equivalent query in MongoDB.


DBMS Lab Workbook (CSL214) | 85
2025-26

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.

{ "_id" : ObjectId("5cc7fe36e37496f1a5e7e268"),"Pname" : "ProductK", "Pnumber" :


45,"Plocation" : ["Delhi","Mumbai","Pune"], "Dnum" : 3}
{ "_id" : ObjectId("5cc7fe36e37496f1a5e7e268"),"Pname" : "ProductT", "Pnumber" :
56,"Plocation" : ["Delhi","Mumbai"], "Dnum" : 15}
{ "_id" : ObjectId("5cc7fe36e37496f1a5e7e268"),"Pname" : "ProductU", "Pnumber" :
5,"Plocation" : "Delhi", "Dnum" : 6}
{ "_id" : ObjectId("5cc7fe36e37496f1a5e7e268"),"Pname" : "ProductL", "Pnumber" :
4,"Plocation" : "Mumbai", "Dnum" : 7}

6) Write a MongoDB query creating a One to Many Relation between a document of


“Project” Collection and “Department” Collection.

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

Operation Syntax Example

>[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

Q3) Point out the wrong statement.


1) sort() modifier sorts the results by age in ascending order
2) Queries in MongoDB return all fields in all matching documents by default
3) To scale the amount of data that MongoDB sends to applications, include a projection
in the queries.
4) None 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 } )

Q5) Which of the following is not a projection operator?


1) $slice
2) $elemMatch
3) $
4) None of the mentioned

Value Added Experiment


Student Name and Roll Number:

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.

Database for [Link] Specialization

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.

2. Write the “Select * from Student” equivalent query in MongoDB.


DBMS Lab Workbook (CSL214) | 91
2025-26

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

You might also like