Dbms Lab Manual
Dbms Lab Manual
Question 1:
Create a table called Employee & execute the following.
Employee(EMPNO,ENAME,JOB, MANAGER_NO, SAL, COMMISSION)
1. Create a user and grant all permissions to the user.
2. Insert any three records in the employee table contains attributes EMPNO,ENAME
JOB, MANAGER_NO, SAL, COMMISSION and use rollback. Check the result.
3. Add primary key constraint and not null constraint to the employee table.
4. Insert null values to the employee table and verify the result.
Solution
1. --creating a DataBase
sudo mysql -u root
CREATE DATABASE COMPANY;
USE COMPANY;
--Table Creation
mysql> CREATE TABLE COMPANY.Employee (
-> EMPNO INT,
-> ENAME VARCHAR(255),
-> JOB VARCHAR(255),
-> MANAGER_NO INT,
-> SAL DECIMAL(10, 2),
-> COMMISSION DECIMAL(10, 2)
-> );
2. mysql> INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
-> VALUES (1, 'Kavana Shetty', 'Manager', NULL, 5000.00, 1000.00);
mysql> INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
VALUES (2, 'Ram Charan', 'Developer', 1, 4000.00, NULL);
mysql> INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
VALUES (3, 'Honey Singh', 'Salesperson', 2, 3000.00, 500.00);
5. mysql> INSERT INTO Employee (EMPNO, ENAME, JOB, MANAGER_NO, SAL, COMMISSION)
-> VALUES (4, 'Ranjan', 'Manager', NULL, 5000.00, 1000.00);
Question 2:
Create a table called Employee that contain attributes EMPNO,ENAME,JOB, MGR,SAL &
execute the following.
1. Add a column commission with domain to the Employeetable.
2. Insert any five records into the table.
3. Update the column details of job
4. Rename the column of Employ table using alter command.
5. Delete the employee whose Empno is 105.
Solution
2. mysql> INSERT INTO Employee (EMPNO, ENAME, JOB, MGR, SAL, COMMISSION)
-> VALUES
-> (101, 'Radha Bai', 'Manager', NULL, 5000.00, 1000.00),
-> (102, 'Krishna Kumar', 'Developer', 101, 4000.00, NULL),
-> (103, 'Abdul Sattar', 'Salesperson', 102, 3000.00, 500.00),
Question 3:
Queries using aggregate functions(COUNT,AVG,MIN,MAX,SUM),Group by,Orderby.
Employee(E_id, E_name, Age, Salary)
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 Employee table.
5. Find salaries of employee in Ascending Order.
6. Find grouped salaries of employees.
Question 4:
Create a row level trigger 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)
-- INSERT TRIGGER
DELIMITER //
DELIMITER ;
-- UPDATE TRIGGER
DELIMITER //
DELIMITER ;
-- DELETE TRIGGER
DELIMITER //
DELIMITER ;
Question 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.
CUSTOMERS(ID,NAME,AGE,ADDRESS,SALARY)
USE COMPANY05;
DELIMITER //
DELIMITER ;
Question 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.
USE ROLLCALL;
birth_date DATE
);
DELIMITER //
DELIMITER ;
Question 7:
Install an Open Source NoSQL Data base MongoDB & perform basic CRUD(Create, Read,
Update & Delete) operations. Execute MongoDB basic Queries using CRUD operations.
Please refer to the blog below which contains detailed procedure of installing Open
Source NoSQL Data base MongoDB.
https://moodle.sit.ac.in/blog
1. Start MongoDB.
Launch the MongoDB daemon using the following command:
sudo systemctl start mongod
bookDB> db.createCollection("ProgrammingBooks")
This command will create an empty ProgrammingBooks collection in the current database
(bookDB).
5. INSERT operations
a. Insert 5 Documents into the ProgrammingBooks Collection :
Now, insert 5 documents representing programming books into
the ProgrammingBooks collection using the insertMany() method:
bookDB> db.ProgrammingBooks.insertMany([
{
title: "Clean Code: A Handbook of Agile Software Craftsmanship",
author: "Robert C. Martin",
category: "Software Development",
year: 2008
},
{
title: "JavaScript: The Good Parts",
author: "Douglas Crockford",
category: "JavaScript",
year: 2008
},
{
title: "Design Patterns: Elements of Reusable Object-Oriented Software",
author: "Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides",
category: "Software Design",
year: 1994
},
{
title: "Introduction to Algorithms",
author: "Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein",
category: "Algorithms",
year: 1990
},
{
title: "Python Crash Course: A Hands-On, Project-Based Introduction to Programming",
author: "Eric Matthes",
category: "Python",
year: 2015
}
])
bookDB> db.ProgrammingBooks.insertOne({
title: "The Pragmatic Programmer: Your Journey to Mastery",
author: "David Thomas, Andrew Hunt",
category: "Software Development",
year: 1999
})
bookDB> db.ProgrammingBooks.find().pretty()
[
{
_id: ObjectId('663eaaebae582498972202df'),
title: 'Clean Code: A Handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin',
category: 'Software Development',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e0'),
title: 'JavaScript: The Good Parts',
author: 'Douglas Crockford',
category: 'JavaScript',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e1'),
title: 'Design Patterns: Elements of Reusable Object-Oriented Software',
author: 'Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides',
category: 'Software Design',
year: 1994
},
{
_id: ObjectId('663eaaebae582498972202e2'),
title: 'Introduction to Algorithms',
author: 'Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein',
category: 'Algorithms',
year: 1990
},
{
_id: ObjectId('663eaaebae582498972202e3'),
title: 'Python Crash Course: A Hands-On, Project-Based Introduction to Programming',
author: 'Eric Matthes',
category: 'Python',
year: 2015
},
{
_id: ObjectId('663eab05ae582498972202e4'),
title: 'The Pragmatic Programmer: Your Journey to Mastery',
author: 'David Thomas, Andrew Hunt',
category: 'Software Development',
year: 1999
}
]
_id: ObjectId('663eaaebae582498972202df'),
title: 'Clean Code: A Handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin',
category: 'Software Development',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e0'),
title: 'JavaScript: The Good Parts',
author: 'Douglas Crockford',
category: 'JavaScript',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e3'),
title: 'Python Crash Course: A Hands-On, Project-Based Introduction to Programming',
author: 'Eric Matthes',
category: 'Python',
year: 2015
}
]
7. Update Operations
a. Update a Single Document
To update a specific book (e.g., change the author of a book):
bookDB>db.ProgrammingBooks.updateOne(
{ title: "Clean Code: A Handbook of Agile Software Craftsmanship" },
{ $set: { author: "Robert C. Martin (Uncle Bob)" } }
)
category: 'JavaScript',
year: 2008
}
]
bookDB> db.ProgrammingBooks.updateMany(
{ year: { $lt: 2010 } },
{ $set: { category: "Classic Programming Books" } }
)
//verify the update operation by displaying books published before year 2010
bookDB> db.ProgrammingBooks.find({ year: { $lt: 2010 } }).pretty()
[
{
_id: ObjectId('663eaaebae582498972202df'),
title: 'Clean Code: A Handbook of Agile Software Craftsmanship',
author: 'Robert C. Martin (Uncle Bob)',
category: 'Classic Programming Books',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e0'),
title: 'JavaScript: The Good Parts',
author: 'Douglas Crockford',
category: 'Classic Programming Books',
year: 2008
},
{
_id: ObjectId('663eaaebae582498972202e1'),
title: 'Design Patterns: Elements of Reusable Object-Oriented Software',
author: 'Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides',
category: 'Classic Programming Books',
year: 1994
},
{
_id: ObjectId('663eaaebae582498972202e2'),
title: 'Introduction to Algorithms',
author: 'Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein',
category: 'Classic Programming Books',
year: 1990
},
{
_id: ObjectId('663eab05ae582498972202e4'),
title: 'The Pragmatic Programmer: Your Journey to Mastery',
author: 'David Thomas, Andrew Hunt',
category: 'Classic Programming Books',
year: 1999
}
]
8. Delete Operations
a. Delete a Single Document
To delete a specific book from the collection (e.g., delete a book by title):
You can check whether the specified document is deleted by displaying the contents of the
collection.
You can check whether the specified documents were deleted by displaying the contents of the
collection.
bookDB> db.ProgrammingBooks.drop()
true
bookDB>