Dbms Lab Manual
Dbms Lab Manual
desc Employee;
2.Insert the any three records in the employee table contains attributes EMPNO,ENAME JOB, MANAGER_NO,
START TRANSACTION;
INSERT INTO Employee VALUES (1, 'John Doe', 'Manager', 0, 5000, 1000);
INSERT INTO Employee VALUES (2, 'Jane Smith', 'Developer', 1, 4000, NULL);
INSERT INTO Employee VALUES (3, 'Alice Johnson', 'Analyst', 1, 3500, 500);
ROLLBACK;
3.Add primary key constraint and not null constraint to the employee table.
Table altered
Table altered
4.Insert null values to the employee table and verify the result.
INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION) VALUES
(4, ‘shyam sharan’, NULL, 0, 5000, 1000);
Table created
ALTER TABLE Employee ADD commission decimal(10, 2) DEFAULT 0.00 NOT NULL;
Prima
Data Leng Precisi Sca ry Nulla Defa Comm
Table Column Type th on le Key ble ult ent
EMPLOYE NUMBE
EMPNO 22 - 0 - - -
E39 R
VARCH
ENAME 20 - - - - -
AR2
VARCH
JOB 10 - - - - -
AR2
MANAGER NUMBE
22 - 0 - - -
_NO R
NUMBE
SAL - 10 2 - - -
R
Table altered.
Table altered.
1 row(s) deleted.
1.Create Employee table containing all Records E_id, E_name, Age, Salary.
Create Table Employee(E_id int, E_name varchar(20), Age integer, Salary decimal(10,2));
Table created
desc Employee;
Create table CUSTOMERS01(ID int primary key,NAME varchar(20) NOT NULL,AGE int,ADDRESS
varchar(30),SALARY decimal(10,2));
Table created.
3. Creating trigger
INSERT INTO CUSTOMERS01 VALUES (15, 'john', 30, 'abc street', 30000);
1 row(s) inserted.
Old salary: 25000
New salary: 26000
Salary difference: 1000
1 row(s) updated.
1 row(s) deleted.
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)
-- Declare variables
DECLARE
E_id Employee.E_id%TYPE;
E_name Employee.E_name%TYPE;
Age Employee.Age%TYPE;
Salary Employee.Salary%TYPE;
-- Declare cursor
CURSOR employee_cursor IS
SELECT E_id, E_name, Age, Salary
FROM Employee01;
OUTPUT:
Employee ID: 8, Name: x, Age: 45, Salary: 20000
Statement processed.
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.
CREATE TABLE N_RollCall7( id INT PRIMARY KEY, name VARCHAR(25), roll varchar(20));
Table created.
CREATE TABLE O_RollCall7( id INT PRIMARY KEY, name VARCHAR(25), roll varchar(20));
Table created.
ID NAME ROLL
4 D m
3 bcd n
5 bch l
2 B o
6 A x
Select * from N_RollCall7;
ID NAME ROLL
2 B o
5 Bch u
1 Bc k
6 A x
DECLARE
v_count NUMBER;
CURSOR c_new_rollcall IS
SELECT id, name, roll
FROM N_RollCall7;
BEGIN
FOR new_rec IN c_new_rollcall LOOP
-- Check if the record already exists in O_RollCall7
SELECT COUNT(*)
INTO v_count
FROM O_RollCall7
WHERE id = new_rec.id;
1 row(s) inserted.
ID NAME ROLL
4 d m
3 bcd n
1 bc k
5 bch l
2 b o
6 a x
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.
Step 4: Now check if the installation process is done correctly and everything is working fine.
Gothrough the following command:
Step 5: MongoDB services can be started and stopped with the use of following commands: To
stoprunning the MongoDB service, use command :
MongoDB service has been stopped and can be checked by using the status command:
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.
// more documents
]);
Example:
db.users.insertOne({ name: "John Doe", age: 30, email: "[email protected]"});
output:
{
"acknowledged" : true,
"insertedId" : ObjectId("669f39fa348de2397e445c0b")
}
2. Read (Query)
To read or retrieve data from a MongoDB collection, you use the find() method.
db.collection('yourCollection').find();
Example:
db.users.find();
output:
{ "_id" : ObjectId("669f39fa348de2397e445c0b"), "name" : "John Doe", "age" : 30, "email" :
"[email protected]" }
3. Update
To update existing documents in a MongoDB collection, you use the updateOne()or updateMany()
methods.
Example:
db.users.updateOne({ name: "John Doe" },{ $set: { age: 31 } });
output:
4. Delete
To delete documents from a MongoDB collection, you use the deleteOne()or deleteMany()methods.
Example:
output:
Example:
db.users.insertMany([
{ name: "Jane Smith", age: 25, email: "[email protected]" },
{ name: "Michael Brown", age: 35, email: "[email protected]" }
]);
output:
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("669f3aae348de2397e445c0c"),
ObjectId("669f3aae348de2397e445c0d")
]
}
Example:
db.users.find({}, { name: 1, age: 1 });
output:
Example:
db.users.find({ age: { $gte: 30 } });
output:
Example:
db.users.updateMany(
{ age: { $gte: 30 } },
{ $set: { status: "senior" } }
);
output:
Example:
db.users.deleteMany({ age: { $lt: 30 } });
output:
{ "acknowledged" : true, "deletedCount" : 1 }