Dbms 2022 Scheme Lab Exercise Solution-1
Dbms 2022 Scheme Lab Exercise Solution-1
2. -- Start a transaction
START TRANSACTION;
Note: MySQL does not support defining domains directly. Instead, you specify the data type
and any constraints associated with the column directly in the ALTER TABLE statement.
Job is a column in the employee table, and we are changing it's data type to
VARCHAR(100)
1. Create Table Employee(E_id int, E_name varchar(20), Age integer, Salary decimal(10,2));
Note: Insert values for Employee table for minimum of 5 rows, before executing the
following queries.
Crate table using the following for creating table and inserting values, before executing the
query.
Crate table using the following for creating table and inserting values, before executing the
query.
Create Table Employee(E_id int, E_name varchar(20), Age integer, Salary decimal(10,2));
1. DECLARE
z_empid Employee.E_id%TYPE;
z_empname Employee.E_name%TYPE;
z_age Employee.Age%TYPE;
z_salary Employee.Salary%TYPE;
CURSOR employee_cursor IS -- declaring a cursor
SELECT E_id,
E_name,
Age,
Salary
FROM Employee;
BEGIN
OPEN employee_cursor; -- opening the cursor
LOOP
FETCH employee_cursor -- fetching records from the cursor
INTO z_empid,
z_empname,
z_age
z_salary;
EXIT
WHEN employee_cursor%NOTFOUND;
SELECT CONCAT('Employee ID: ', E_id, ', Name: ', e_name, ', Age: ', age, ', Salary: ',
salary) AS employee_info;
END LOOP;
CLOSE employee_cursor; --closing the cursor
END;
/
DELIMITER //
-- Close cursor
CLOSE n_cursor;
END //
We declare variables to store data retrieved from the N_RollCall and O_RollCall tables.
We declare a cursor (n_cursor) to loop through the N_RollCall table.
Inside the loop, we fetch data from N_RollCall and check if the same data exists in
O_RollCall. If it doesn't, we insert it into O_RollCall.
The cursor is closed at the end of the procedure.
Q 7) Install an Open Source NoSQL Data base MangoDB & perform basic CRUD(Create,
Read, Update & Delete) operations. Execute MangoDB basic Queries using CRUD
operations.
Also, If you have an Intel computer, it should be at least a Sandy Bridge Core processor, a
later version, or a Tiger Lake Celeron or Pentium processor. It would help to have a
Bulldozer processor or a later version for AMD computers.
Step 2: You need to select a specific version, platform, and package per the project
requirement. For Windows, we must choose Version 7.0.0 or current, Platform Windows OS
Platform, and MSI Package as demonstrated below. you can click the download button now.
It allows you to download the setup.
Step 3: Navigate to the installer now. This is where the setup is downloaded. Double-click on
the MSI file to start the installation. The Installation Screen appears as shown below. After
this, click on the next option.
Step 4: An installation wizard should pop up as depicted below. Read the End-User License
Agreement, accept the terms and conditions, and select the “Next” button.
Step 5: Now, select the Complete or Custom setup type. Select the complete setup option,
which installs MongoDB at the default location. Select Complete Setup and then click the
"Next" option as outlined below.
Step 6: Click on the “Install MongoD as a Service” button and Select the “Next” option as
captured below.
Step 7: After this, you will be given the option of installing MongoDB Compass. Uncheck
the box if you do not want it installed on your device, and click the “Next” button to proceed
further.
Step 8: Now allow administrator access and click the “Install” button to start the MongoDB
Installation as shown below.
Step 10: After the Installation, click the ‘Finish’ button to close the installer screen.
]
MongoDB Shell Installation on Windows
After Installing MongoDB, we will install its Shell that interacts with MongoDB
deployments. It must be installed separately, as the MongoDB installer does not include it.
Follow the below steps to install MongoDB Shell on Windows.
Step 2: You can extract the downloaded zip file and store it in the desired location. You will
locate the bin folder, as shown in the picture below in the next step.
Step 3: Click on the ‘mongosh’ file to launch the MongoDB shell. The Shell would appear as
depicted below:
Step 1: Navigate to the MongoDB installation directory on “C Drive.” Go to the Server> 7.0
> bin folder. Now, you can create a copy of the path as shown below.
Step 2: Next. you can navigate to the windows search. You can type ‘environment variable’
into the search box. After that, choose the ‘Edit environment variables for your account’ item.
Step 3: Now you can select the environment variables in the advanced settings as shown
below:
Step 5: Select “New” to set a new path variable. After this, paste the copied path here, then
click “OK.” The environmental variables have been added successfully.
Step 6: You can run the MongoDB local server from any path in your computer’s terminal.
After you’ve added the environment variable to the system, use the Command Prompt to run
the ‘mongod - -version‘ command to see if MongoDB is appropriately installed. It should
produce the following result:
Starting with MongoDB 4.0, you can install MongoDB as a Windows service or simply the
binaries. Optional. Select Install MongoDB Compass (Default) to have the wizard install
MongoDB Compass. When you’re finished, click Install. Mongosh is not included in the.msi
installer.
No, 32-bit x86 platforms are not supported by MongoDB. It stopped supporting 32-bit
platforms with MongoDB 3.2. MongoDB supports a64bit x86 processor or its equivalent.
3. If a MongoDB database does not exist in your system, what would be the result?
MongoDB typically doesn't need a specific schema to store data. It allows you to change the
schema without creating any new database.
First, go to the MongoDB installation directory. Then execute the ‘mongod’ command to
initialize the mongoDB server. After that, you can use the –dbpath flag to indicate if the data
directory is not in the default location.
Conclusion
MongoDB provides a versatile and scalable solution for a variety of data needs. It has
changed the database environment with its flexible features. This article should have given
you useful insights on mongoDB. You have also learned how to install MongoDB on your
system. If you desire to explore more about MongoDB, you can sign up for a MindMajix's
MongoDB training. You will get certification and stay ahead in the job market.
CRUD Operations
MongoDB is a popular document-oriented NoSQL database that allows users to store and
manipulate data in a flexible, schema-less manner. One of the core functionalities of
MongoDB is its ability to perform CRUD (Create, Read, Update, and Delete) operations
on documents in its collections. In this article, we will provide a beginner’s guide to
performing CRUD operations in MongoDB, with examples for each operation.
For example, let’s say we want to create a new document to represent a user. We could define
the structure of the document like this:
{
"name": "John Smith",
"email": "[email protected]",
"age": 32
}
To insert this document into a MongoDB collection, we would use the insertOne() method.
Here's an example:
db.users.insertOne({
"name": "John Smith",
"email": "[email protected]",
"age": 32
})
This would create a new document in the users collection with the specified fields and values.
Reading Documents
To read documents from a MongoDB collection, we use the find() method. This method
returns a cursor to the documents that match the specified query. For example, to find all
documents in the users collection, we could run:
db.users.find()
This would return a cursor to all documents in the users collection.
We could also specify a query to filter the results. For example, to find all users with an age
greater than 30, we could run:
Updating Documents
To update a document in MongoDB, we use the updateOne() method. This method takes two
parameters: a query to match the document to be updated, and an update object to specify the
changes to be made. For example, to update the email address of a user with the name "John
Smith", we could run:
db.users.updateOne(
{ "name": "John Smith" },
{ $set: { "email": "[email protected]" } }
)
This would update the email address of the first document in the users collection where the
name field is "John Smith".
Deleting Documents
To delete a document in MongoDB, we use the deleteOne() method. This method takes a
query to match the document to be deleted. For example, to delete the first document in the
users collection where the name field is "John Smith", we could run: