Dbms Lab Manual - Svit
Dbms Lab Manual - Svit
(Affiliated to VTU, Belagavi, Approved by AICTE, New Delhi and Govt. of Karnataka)
Accredited by NBA, New Delhi (CSE, ISE, ECE, MECH, CIVIL), NAAC-‘A’ Grade
Rajanukunte, Bengaluru – 560 064
Tel: 080-2846 8196, email: [email protected] web: www.saividya.ac.in
VISION MISSION
To provide quality education and skilled training
to produce dedicated engineers and managers.
Contribute dedicated, skilled, To promote research, innovation, and ethical
intelligent engineers and practices by creating supportive environment.
business administrators to To undertake collaborative projects with academia
architect strong India and the and industry that transform young minds into
world. Socially Responsible Citizen and Globally
Competent Professionals.
To enhance personality traits which lead to
entrepreneurship qualities among the students.
Compiled by:
Trademark
Edition: 2023-24
Document Owners
The primary contacts for questions regarding this document are:
[email protected]
Contact email id: 2. [email protected]
1.
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
DEPARTMENT VISION
DEPARTMENT MISSION
Experiment 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 the 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 the table and granting permissions:
Creating a new user
SQL>CREATE USER user_name IDENTIFIED BY password;
Granting all permissions to the new user
SQL>GRANT ALL PRIVILEGES ON to user_name;
Creating the Employee table
SQL> CREATE TABLE Employee (
EMPNO INT,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MANAGER_NO INT,
SAL DECIMAL(10, 2),
COMMISSION DECIMAL(10, 2)
);
2. Inserting three records into the Employee table and rolling back:
Inserting records:
SQL>INSERT INTO Employee values(1, 'John Doe', 'Manager', 101, 20000.00,
2000.00);
SQL>INSERT INTO Employee values(2, 'Jane Smith', 'Developer', 102,
45000.00, 1500.00);
Experiment 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 Employee table.
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:
SQL>CREATE TABLE Employee (
EMPNO INT PRIMARY KEY,
ENAME VARCHAR(50),
JOB VARCHAR(50),
MGR INT,
SAL DECIMAL(10, 2));
2. Insert five records into the table
SQL>INSERT INTO Employee VALUES (101, 'John Doe', 'Manager', NULL, 5000.00);
SQL>INSERT INTO Employee VALUES (102, 'Jane Smith', 'Salesperson', 101, 3000.00);
SQL>INSERT INTO Employee VALUES (103, 'Michael Johnson', 'Salesperson', 101,
3200.00);
SQL>INSERT INTO Employee VALUES (104, 'Emily Brown', 'Clerk', 102, 2500.00);
SQL>INSERT INTO Employee VALUES (105, 'David Williams', 'Analyst', 101, 4500.00);
3. Update the column details of job
SQL> UPDATE Employee SET JOB = 'Senior Salesperson' WHERE EMPNO = 103;
Experiment 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 employeetable
3. Find the Maximum age from employee table.
4. Find the Minimum age from employeetable.
5. Find salaries of employee in Ascending Order.
6. Find grouped salaries of employees.
1. Create Employee table containing all Records E_id, E_name, Age, Salary.
SQL> CREATE TABLE Employee (
E_id INT PRIMARY KEY,
E_name VARCHAR(25),
Age INT,
Salary DECIMAL(10, 2)
);
SQL> insert into Employee values(101,’Shravya’,19,20000);
SQL> insert into Employee values(102,’keerthi’,32,15000);
SQL> insert into Employee values(103,’bhuvan’,18,30000);
SQL> insert into Employee values(104,’akash’,55,50000);
SQL> insert into Employee values(105,’Sumanth’,20,20000);
Experiment 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)
Solution
SQL>create table CUSTOMERS (
ID INT PRIMARY KEY,
NAME varchar2(20) NOT NULL,
AGE INT,
ADDRESS varchar2(25) ,
SALARY Decimal);
insert into CUSTOMERS values (111, 'kavana', 20 , 'Bengaluru', 29000)
SQL>insert into CUSTOMERS values (222, 'Darshan', 35 , 'Hassan', 15000)
Trigger created.
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
CREATE TABLE Employee (
E_id INT PRIMARY KEY,
E_name VARCHAR(255),
Age INT,
Salary DECIMAL(10, 2)
);
-- 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 Employee;
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
DECLARE
v_count NUMBER;
CURSOR c_new_rollcall IS
SELECT id, name, roll
FROM N_RollCall2;
BEGIN
FOR new_rec IN c_new_rollcall LOOP
-- Check if the record already exists in O_RollCall2
SELECT COUNT(*)
INTO v_count
FROM O_RollCall2
WHERE id = new_rec.id;
END;
Experiment no: 7
Install an Open Source NoSQL Data base MangoDB & perform basic CRUD(Create, Read,
Update & Delete) operations. Execute MangoDB basic Queries using CRUD operations.
Solution
Installation:
Download MongoDB:
Visit the official MongoDB website and download the MongoDB Community Server
according to your operating system.
Install MongoDB:
Follow the installation instructions provided for your operating system.
Start MongoDB:
After installation, start the MongoDB server. On most systems, you can do this by
running mongod in your terminal or command prompt.
1. Connect to MongoDB:
Open a new terminal or command prompt window and run the mongo command to
open the MongoDB shell.
2. Create Database:
To create a new database, use the use command followed by the database name.
For example: use mydatabase
3. Create Collection:
Collections in MongoDB are analogous to tables in relational databases. To create a
collection, you can simply start adding documents to it. MongoDB will create the