Dbms Lab Manual Bcs403-New-1
Dbms Lab Manual Bcs403-New-1
Engineering
Subject
Department of Computer Science and Engineering
Code:
BCS403
(ARTIFICIAL INTELLIGENCE)
Prepared by : Prof. KARTHIKEYAN.A.N
Dept. of CSE (AI), SVCE, Bengaluru.
Semester: 4, Scheme:2022
Academic Year: 2024-2025
Database Management Systems
SQL Commands
SQL commands are instructions used to communicate with the database to perform specific task that work with
data. SQL commands can be used not only for searching the database but also to perform various other
functions like, for example, you can create tables, add data to tables, or modify data, drop the table, set
permissions for users.
4) 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) 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)
Commit command
Commit command is used to permanently save any transaction into database.
Rollback command
This command restores the database to last commited state. It is also use with savepoint command to jump to a
savepoint in a transaction.
Savepoint command
savepoint command is used to temporarily save a transaction so that you can roll back to that point whenever
necessary.
Course Objective:
DBMS is having the integrated lab with the following objectives,
To Provide a strong foundation in database concepts, technology, and practice.
To Practice SQL programming through a variety of database problems.
To Understand the relational database design principles.
To Demonstrate the use of concurrency and transactions in database.
To Design and build database applications for real world problems.
To become familiar with database storage structures and access techniques
Course Outcomes
Level of
CO’s Statement: After Completion of the course the student will be able to Blooms
Taxonomy
C232.1 CO1: To understand the concepts of DBMS and would have acquired skills to
analyze the real-world problem domains in the context of DBMS and L3
demonstrate the same through ER diagram.
C232.2 CO2: To apply and demonstrate with understanding of relational query L3
serializability, and to develop database programming skills using SQL and JDBC.
C232.5 CO5: To Classify different concurrency control strategies and recovery L3
CO-PO mapping
CO CKL PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
\
PO
PKL 3 5 6 5 6 3 3 3 NA M 3 M 3 3
CO1 2 3 2 1 2 1 2 3 3 - 3 2 3 3 3
CO2 2 3 3 3 2 1 3 3 3 - 3 2 3 3 3
CO3 3 3 2 3 2 3 2 3 2 - 3 2 3 3 3
CO4 3 3 2 3 2 3 2 3 2 - 3 2 3 3 3
CO5 3 3 2 3 2 3 3 3 2 - 3 2 3 3 3
PROGRAMME OUTCOMES:
1. Engineering Knowledge: Apply knowledge of mathematics, science, engineering fundamentals and an
engineering specialization to the solution of complex engineering problems.
2. Problem Analysis: Identify, formulate, research literature and analyze complex engineering problems
reaching substantiated conclusions using first principles of mathematics, natural sciences and engineering
sciences
3. Design/ Development of Solutions: Design solutions for complex engineering problems and design system
components or processes that meet specified needs with appropriate consideration for public health and
safety, cultural, societal and environmental considerations.
4. Conduct investigations of complex problems using research-based knowledge and research methods
including design of experiments, analysis and interpretation of data and synthesis of information to provide
valid conclusions.
5. Modern Tool Usage: Create, select and apply appropriate techniques, resources and modern engineering
and IT tools including prediction and modeling to complex engineering activities with an under- standing of
the limitations.
6. The Engineer and Society: Apply reasoning informed by contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to professional engineering
practice.
7. Environment and Sustainability: Understand the impact of professional engineering solutions in societal
and environmental contexts and demonstrate knowledge of and need for sustainable development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
engineering practice.
9. Individual and Team Work: Function effectively as an individual, and as a member or leader in diverse
teams and in multi-disciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as being able to comprehend and write effective reports and
design documentation, make effective presentations and give and receive clear instructions.
11. Life-long Learning: Recognize the need for and have the preparation and ability to engage in independent
and life- long learning in the broadest context of technological change.
12. Project Management and Finance: Demonstrate knowledge and understanding of engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to manage
projects and in multidisciplinary environments
Concept Map
Course Contents
2. Create a table called Employee that contain attributes EMPNO,ENAME,JOB, MGR,SAL & 3
execute the following.
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 employeetable.
5. Find salaries of employee in Ascending Order.
6. 6.Find grouped salaries of employees.
4. Create a row level trigger for the customers table that would fire for INSERT or UPDATE 6
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)
5. Create cursor for Employee table & extract the values from the table. Declare the 8
variables, Open the cursor & extract the values from the cursor. Close the cursor.
Employee(E_id,
E_name, Age, Salary)
6. Write a PL/SQL block of code using parameterized Cursor, that will merge the data 10
available in 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.
7. Install an Open Source NoSQL Data base MangoDB & perform basic CRUD(Create, Read, 12
Update & Delete) operations. Execute MangoDB basic Queries using CRUD operations.
Database Management System BCS403
INTRODUCTION TO ORACLE
SQL
SQL stands for Structured Query Language. SQL is used to create, remove, alter the
database and database objects
in a database management system and to store, retrieve, update the data in a database.
SQL is a standard language
for creating, accessing, manipulating database management system. SQL works for all
modern relational database
management systems, like SQL Server, Oracle, MySQL, etc.
SQL commands can be categorized into five categories based on their functionality
SQL commands can be categorized into five categories based on their functionality
Anbulakshmi S CSE(DS)
Database Management System BCS403
);
Suppose, you want to create a Student table with five columns in the SQL
database. To do this, you have to write the following DDL command:
Example 1:
CREATE TABLE
Student (
Roll_No. int ,
First_Name varchar (20) ,
Last_Name varchar (20) ,
Age int ,
Marks int,
Dob Date
);
SQL>desc Student;
Example 2:
create table Employee
(
empid varchar(10),
empname varchar(20) ,
gender varchar(7),
age number(3),
dept varchar(15) ,
doj Date
);
SQL> desc Employee
Example 3:
create table BOOK
(
Book_id
varchar(4), Title
varchar(10),
Publisher_name
varchar(10), Pub_year int
);
SQL> desc BOOK;
KARTHIKEYAN.A.N- 2
CSE-AI CSE(DS)
Database Management System BCS403
KARTHIKEYAN.A.N- 3
CSE-AI CSE(DS)
Database Management System BCS403
2. ALTER
This command is used to add, delete or change columns in the existing table. The
user needs to know the existing table name and can do add, delete or modify
tasks easily.
Syntax: –
.ADD:
SQL> alter table employee add(designation varchar(15));
Table altered.
II.MODIFY
SQL> alter table employee modify (designation varchar(20));
Table altered
Example 1:
ALTER TABLE
Student ADD CGPA
number; SQL>desc
Student; Example 2:
ALTER TABLE
Employee ADD Salary
number;
SQL>desc Employee;
Example 3:
ALTER TABLE BOOK
ADD Author_nmae varchar(20);
SQL>desc Student;
KARTHIKEYAN.A.N- 4
CSE-AI CSE(DS)
Database Management System BCS403
KARTHIKEYAN.A.N- 5
CSE-AI CSE(DS)
Database Management System BCS403
3. RENAME:
Syntax –
RENAME <Table Name> To<New_Table_Name>;
Example:
RENAME TABLE Employee To EMP;
4. TRUNCAT:
This command is used to remove all rows from the table, but the structure of the
table still exists.
Syntax –
Syntax to remove an existingtable.
Example:
TRUNCATE TABLE Student;
5. DROP
This command is used to remove an existing table along with its structure from
the Database.
Syntax –
Syntax to drop an existing table.
DROP TABLE table_name;
Example: DROP TABLE Student_info;
DML(DATA MANIPULATION LANGUAGE):
Data manipulation language allows the users to query and manipulate data in
existing schema in object.
It allows following data to insert, delete, update and recovery data inschema
object.
DML COMMANDS:
KARTHIKEYAN.A.N- 6
CSE-AI CSE(DS)
Database Management System BCS403
❖ INSERT
❖ UPDATE
❖ DELETE
1. INSERT
This command is used to enter the information or values into a row. We
can connect one or more records to a single table within a repository using
this instruction.
Syntax:
Insert into Table_ Name Values(column1, column2,.. .);
Example:
CREATE TABLE
Student (
Roll_No int ,
First_Name varchar (20) ,
Last_Name varchar (20) ,
Marks int,
Dob Date
);
SQL>desc Student;
SQL> insert into Student values(‘01’,’Adit,’k’’,25,’11-02-2004’);
SQL> insert into Student values(02,“Arpitha”,”S”, 20,’21-12-2003’);
SQL> insert into Student values(03,“Jorge”,”D”, 20, 18,’10-08-2001’);
Insert 2 more rows.
SQL>desc Student;
2. UPDATE
This allows the user to update the particular column value using the
where clause condition. This command is used to alter existing table
records.
Syntax:
UPDATE <table_ name>
SET <column_ name = value>
WHERE condition;
Anbulakshmi S CSE(DS) 5
Database Management System BCS403
Anbulakshmi S CSE(DS) 5
Database Management System BCS403
Example:
UPDATE Students
SET Marks= 21
WHERE First_ name = “Arpitha”;
SQL>desc Students;
3. DELETE
a) Delete some rows
DELETE statement is used to delete rows from a table. Generally DELETE
statement removes one or more records from a table.
Syntax:
DELETE FROM table_name WHERE condition;
Example:
Delete from Students where Roll_no=’111’;
Anbulakshmi S CSE(DS) 6
Database Management System BCS403
Example:
Select * from Students;
SQL> desc Students;
Example:
SELECT DISTINCT Roll_No FROM Students;
Example:
SELECT * FROM students
WHERE students_name IN ( Arpitha,Jorge);
Anbulakshmi S CSE(DS) 7
Database Management System BCS403
Example:
SELECT * FROM student WHERE mark BETWEEN 80 and100;
6.Renaming:
The select statement can be used to rename either a column or the entire table.
Syntax:
Renaming a column:
SELECT column name AS new name FROM table_name;
Example:
Renaming a table:
Example:
RENAME Student TO Stu_details;
7.SELECT DATE
It is used to retrieve a date from a database. If you want to find a particular date
from a database, you can use this statement.
Syntax:
SELECT Column_Names(S) from table-name
WHERE condition(date_column);
8. SELECT NULL
Null values are used to represent missing unknown data.
There can be two conditions:
Anbulakshmi S CSE(DS) 8
Database Management System BCS403
Syntax:
SELECT COLUMN_NAME(S) FROMTABLE_NAME
WHERE COLUMN_NAME IS NOT NULL;
Example:
SELECT Student_name, Marks FROM STUDENTS
WHERE MARKS IS NOT NULL;
ORDER BY Clause
ORDER BY is a clause in SQL which shows the result-set of the SELECT statement
in either ascending or descending order.
a) with onerow
Syntax:
SELECT Column_Name FROM Table_Name
ORDER BY Column_Name;
Example:
SELECT * FROM Students ORDER BYReg_no;
b) With Multiple
row Syntax:
SELECT Column_Name(S) FROMTable_Name
ORDER BY Column_Name(S);
Example:
SELECT reg_no,first_name,marks FROM Students ORDER BY first_name,
marks;
Anbulakshmi S CSE(DS) 9
Database Management System BCS403
c) Ascending Order(ASC)/DescendingOrder(DESC)
SELECT Column_Name(S) FROM Table_Name
ORDER BY Column_Name(S) ASC;
Example:
SELECT * FROM Students ORDER BY Marks ASC;
d) with WHERE
Clause Syntax:
SELECT Column_Name(S)FROM Table_Name
GROUP BY clause
GROUP BY is an SQL keyword used in the SELECT query for arranging the same
values of a column in the group by using SQL functions.
Syntax:
SELECT Column_Name(S) FROM Table_Name
GROUP BY Column_Name(S);
Example:
SELECT COUNT (marks), Student_name GROUP BY marks;
Anbulakshmi S CSE(DS)0
Database Management System BCS403
c) COUNT() Function
The COUNT() function returns the number of rows in a database table.
Syntax:
COUNT(*)
or
COUNT( [ALL|DISTINCT] expression )
Example:
1. SELECT COUNT(*)
FROM Student;
2. SELECT COUNT(Marks)
FROM Student
GROUP BY marks
HAVING COUNT(*) > 50;
d) SUM() clause
It is used to return the total summed value of an expression.
Syntax:
SELECT SUM(aggregate_expression)
FROM tables
[WHERE conditions];
Example:
SELECT SUM(Marks)
FROM Student
Where roll_no=’111’;
Anbulakshmi S CSE(DS)1
Database Management System BCS403
DCL (DATA CONTROL LANGUAGE)
DCL stands for data control language. DCL commands are used for providing and
taking back the access rights on the database and database objects. DCL
command used for controlling user’s access on the data. Most used DCL
commands are GRANT and REVOKE
GRANT
used to provide access right to theuser.
REVOKE
REVOKE command is used to take back access right from the user, it cancels
access right of the user from the
database object.
Syntax
REVOKE ALL ON Employee FROM user;
TCL commands can rollback and commit data modification in the database. The
most used TCL commands are COMMIT, ROLLBACK, SAVEPOINT, and SET
TRANSACTION.
COMMIT
COMMIT command is used to save or apply the modification in the database.
ROLLBACK
ROLLBACK command is used to undo the modification.
SAVEPOINT
SAVEPOINT command is used to temporarily save a transaction, the transaction
can roll back to this point when it's needed.
Syntax :
Just write COMMIT or ROLLBACK orSAVEPOINT
Anbulakshmi S CSE(DS)2
Database Management System BCS403
Experiment-1
Solutions:
Create a table employee with the given constraints:
SQL> create table employee (empno number,ename varchar2(10), job
varchar2(10),mgr
number,sal number);
SQL> create table employee (empno number,
ename
varchar(10), job
varchar(10),
mgr_no number,
sal number,
commission number );
Table created
SQL>desc employee;
Anbulakshmi S CSE(DS)3
Database Management System BCS403
insert into employee values(105,'pramod','salesman',5678,5000,'50');
Anbulakshmi S CSE(DS)4
Database Management System BCS403
Solutions:
//create user
User created.
Grant succeeded.
Connect c##dbms/dbms403;
Connected.
Anbulakshmi S CSE(DS)5
Database Management System BCS403
Show user;
2. Insert the any three records in the employee table and use
rollback. Check the result
SQL>rollback
Rollback
completed
Anbulakshmi S CSE(DS)6
Database Management System BCS403
Anbulakshmi S CSE(DS)7
Database Management System BCS403
SQL>desc
Employee;
1 row inserted
Anbulakshmi S CSE(DS)8
Database Management System BCS403
Anbulakshmi S CSE(DS)9
Database Management System BCS403
Viva Question:
1. What is data?
Data is a collection of information gathered by observations, measurements,
research or analysis.
2. What is database?
A database is an electronically stored, systematic collection of data. It can
contain any type of data, including words, numbers, images, videos, and files.
3. What is DBMS?
Database Management Systems (DBMS) are software systems used to store,
retrieve, and run queries on data.
7. What is Table?
A table is an arrangement of data in rows and columns, or possibly in a more
complex structure.
Anbulakshmi S
CSE(DS)10
Database Management System BCS403
8. What is a Tuple?
A tuple is an ordered sequence of values. The values can be repeated, but their
number is always finite.
9. What is Columns?
column or pillar in architecture and structural engineering is a structural
element that transmits, through compression, the weight of the structure above
to other structural elements below.
10.What is a query?
A query is a question or a request for information expressed in a formal manner.
Anbulakshmi S
CSE(DS)11
Database Management System BCS403
Experiment-2
Solution:
Table altered.
Anbulakshmi S
CSE(DS)12
Database Management System BCS403
Anbulakshmi S
CSE(DS)13
Database Management System BCS403
Anbulakshmi S CSE(DS) 20
Database Management System BCS403
1 row updated.
Table altered.
SQL>desc
employee;
Anbulakshmi S CSE(DS) 21
Database Management System BCS403
Anbulakshmi S CSE(DS) 22
Database Management System BCS403
Viva Questions
1. What is an Attribute?
A quality, character, or characteristic ascribed to someone or something has
leadership attributes.
Anbulakshmi S CSE(DS) 23
Database Management System BCS403
In DBMS, key attributes refer to the specific fields or columns in a table that are
used to uniquely identify each record in the table.
Anbulakshmi S CSE(DS) 24
Database Management System BCS403
Experiment-3
Solution:
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
SQL>desc Employee;
Anbulakshmi S CSE(DS) 25
Database Management System BCS403
insert into employee
values(50,'pramod',31,8000);
Anbulakshmi S CSE(DS) 26
Database Management System BCS403
Anbulakshmi S CSE(DS) 27
Database Management System BCS403
Anbulakshmi S CSE(DS) 28
Database Management System BCS403
Anbulakshmi S CSE(DS) 29
Database Management System BCS403
Viva Questions
1. What is an Attribute?
A table consists of several records(row), each record can be broken down into
several smaller parts of data known as Attributes. The above Employee table
consist of four attributes, ID, Name, Age and Salary.
An attributes that may have multiple values for the same entity. For example
colors of a car entity.
Anbulakshmi S CSE(DS) 30
Database Management System BCS403
These are attributes other than candidate key attributes in a table. For example
Firstname is a non key attribute as it does not represent the main characteristics of
the entity.
Anbulakshmi S CSE(DS) 31
Database Management System BCS403
Experiment 4:
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)
Solution:
1. Create Customer Table:
Table created.
values(50,'pramod',31,8000,”Mysore”);
Anbulakshmi S CSE(DS) 32
Database Management System BCS403
Anbulakshmi S CSE(DS) 33
Database Management System BCS403
3.Creating trigger
Trigger created.
Previous salary:8000
Current salary: 10000
Salary
difference:2000
Anbulakshmi S CSE(DS) 34
Database Management System BCS403
Anbulakshmi S CSE(DS) 35
Database Management System BCS403
Viva Questions
A primary key is a column whose values uniquely identify every row in a table.
When a "one" table's primary key field is added to a related "many" table in
order to create the common field which relates the two tables, it is called a
foreign key in the "many" table.
For example, the salary of an employee is stored in salary table. The relation is
established via foreign key column “Employee_ID_Ref” which refers
“Employee_ID” field in the Employee table.
6. What is a query?
A query with respect to DBMS relates to user commands that are used to interact
with a data base. The query language can be classified into data definition
language and data manipulation language.
Anbulakshmi S CSE(DS) 36
Database Management System BCS403
7. Define SQL Insert Statement ?
SQL INSERT statement is used to add rows to a table.
SQL Update is used to update data in a row or set of rows specified in the filter
condition.
SQL Delete is used to delete a row or set of rows specified in the filter condition.
ORDER BY clause helps to sort the data in either ascending order to descending
Anbulakshmi S CSE(DS) 37
Database Management System BCS403
Experiment-5:
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)
Solution:
Table created.
employee;
Anbulakshmi S CSE(DS) 38
Database Management System BCS403
Anbulakshmi S CSE(DS) 39
Database Management System BCS403
3. Create the cursor ,extracting the value from Employee table and
close the cursor.
Output:
Anbulakshmi S CSE(DS) 40
Database Management System BCS403
Viva Questions
1. Define Normalization.
Organized data void of inconsistent dependency and redundancy within a database is
called normalization.
2. Enlist the advantages of normalizing database.
Advantages of normalizing database are:
No duplicate entries
Saves storage space
Boasts the query performances.
3. What is Entity?
An entity can be a real-world object, either animate or inanimate, that can be easily
identifiable. For example, in a school database, students, teachers, classes, and
courses offered can be considered as entities.
5. What is Relationship?
The association among entities is called a relationship. For example, an employee
works_at a department, a student enrolls in a course. Here, Works_at and Enrolls
are called relationships.
Anbulakshmi S CSE(DS) 41
Database Management System BCS403
Binary = degree 2
Ternary = degree 3
n-ary = degree n
Anbulakshmi S CSE(DS) 42
Database Management System BCS403
Experiment-6:
Write a PL/SQL block of code using parameterized Cursor, that will merge
the data available in 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.
Solution:
Anbulakshmi S CSE(DS) 43
Database Management System BCS403
Anbulakshmi S CSE(DS) 44
Database Management System BCS403
Procedure created.
SQL>call
roll_details(); Call
completed.
Anbulakshmi S CSE(DS) 45
Database Management System BCS403
Anbulakshmi S CSE(DS) 46
Database Management System BCS403
Viva Questions
Anbulakshmi S CSE(DS) 47
Database Management System BCS403
7. What is DDL?
DDL stands for Data Definition Language. SQL queries like CREATE,
ALTER, DROP and RENAME come under this.
8. What
is DML?
DML stands for Data Manipulation Language. SQL queries like SELECT,
INSERT and UPDATE come under this.
9. Whatis DCL?
DCL stands for Data Control Language. SQL queries like GRANT
and REVOKE come under this.
Anbulakshmi S CSE(DS) 48
Database Management System BCS403
Experiment-7:
Install an Open Source NoSQL Data base MangoDB & perform basic
CRUD(Create, Read,Update & Delete) operations. Execute MangoDB basic
Queries using CRUD operations.
MongoDB is a popular NoSQL database offering flexibility, scalability, and ease of use. Installing
and configuring MongoDB in Ubuntu is a straightforward process, but it requires careful attention
to detail to ensure a smooth setup.
In this guide, we’ll learn how to install and configure MongoDB in Ubuntu. We’ll walk you through
each step, from installation to configuration, enabling you to harness the power of MongoDB on
your Ubuntu system.
Let’s look at the requirements for installing MongoDB in Ubuntu.
MongoDB can be installed on Ubuntu with the use of the following commands. These commands
are easy to run on the terminal and make the installation process handy. Follow the steps given
below to install MongoDB:
Step 1: First you need to update and upgrade your system repository to install MongoDB. Type the
following command in your terminal and then press Enter.
Step 2: Now, install the MongoDB package using ‘apt‘. Type the following command and press
Enter.
Anbulakshmi S CSE(DS) 49
Database Management System BCS403
Step 3: Check the service status for MongoDB with the help of followingcommand:
Step 4: Now check if the installation process is done correctly and everything is working fine. Go
through the following command:
Anbulakshmi S CSE(DS) 50
Database Management System BCS403
the value “1” in ok field indicates that the server is working properly with no errors.
Step 5: MongoDB services can be started and stopped with the use of following commands: To stop
running the MongoDB service, use command :
Anbulakshmi S CSE(DS) 51
Database Management System BCS403
As it can be seen that the service has stopped, to start the service we can use:
sudo systemctl start mongodb
MongoDB provides a command-line interface called the MongoDB shell, which allows you to
interact with the database.
To access the MongoDB shell, simply type the following command in your terminal:
mongo
You are now connected to the MongoDB server, and you can start executing commands
to createdatabases, collections, and documents.
CRUD Operations:
1. Create (Insert)
To create or insert data into a MongoDB collection, you use the insertOne() or
insertMany() methods.
Anbulakshmi S CSE(DS) 52
Database Management System BCS403
{ key2: value2 },
Anbulakshmi S CSE(DS) 53
Database Management System BCS403
// more documents
]);
2. Read (Query)
To read or retrieve data from a MongoDB collection, you use the find() method.
db.collection('yourCollection').find();
condition:
db.collection('yourCollection').find({ key: value });
3. Update
To update existing documents in a MongoDB collection, you use the updateOne() or updateMany()
methods.
db.collection('yourCollection').updateOne(
);
db.collection('yourCollection').updateMany(
);
4. Delete
To delete documents from a MongoDB collection, you use the deleteOne() or deleteMany() methods.
Anbulakshmi S CSE(DS) 54
Database Management System BCS403
db.collection('yourCollection').deleteMany({ key: value });
Anbulakshmi S CSE(DS) 55
Database Management System BCS403
Viva Questions
CRUD is the acronym for CREATE, READ, UPDATE and DELETE. These terms describe
the four essential operations for creating and managing persistentdata elements, mainly
inrelational and NoSQL databases.
You can perform update, insert and delete operation in the Grid. While performingthese
operations, the corresponding event is invoked. In that event SQL query is used to update the
database. The events for performing CRUD operation are declared.
The MongoDB shell provides the following methods to update documents in acollection:
1. To update a single document, use db. collection. updateOne().
2. To update multiple documents, use db. collection. updateMany() .
3. To replace a document, use db. collection. replaceOne().
The basic methods of interacting with a MongoDB server are called CRUD operations. CRUD
stands for Create, Read, Update, and Delete. These CRUDmethods are the primary ways you will
manage the data in your databases.
CRUD stands for Create, Read, Update, and Delete. These are the four fundamental operations
of persistent storage. In the context of RESTful APIs , they correspond to the HTTP methods
POST, GET, PUT/PATCH, and DELETE.
Several ways can be employed to create and remove collections in MongoDB. Of which one
way is by using db. Create Collection (name, options). MongoDB creates a collection for an
inserted command automatically if no similar collectionalready exists in the MongoDB
database.
Anbulakshmi S CSE(DS) 56