Dbms Lab Manual - Bcs403
Dbms Lab Manual - Bcs403
INSERT INTO Employee VALUES (2, 'Jane Smith', 'Developer', 1, 40000.00, 500.00);
1 row inserted.
INSERT INTO Employee VALUES (3, 'Alice Johnson', 'Analyst', 1, 35000.00, NULL);
1 row inserted.
commit;
Output: Commit complete.
rollback;
Output:
Output:
Table EMPLOYEE altered.
INSERT INTO Employee VALUES(NULL, 'Test Employee', 'Tester', NULL, NULL, NULL);
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 Employee table using alter command.
5. Delete the employee whose Empno is 105.
3500.00, 100.00);
Output: 1 row inserted
INSERT INTO Employee VALUES (104, 'Bob Brown', 'Analyst', 102,
4500.00, 180.00);
Output: 1 row inserted
INSERT INTO Employee VALUES (105, 'Emma Davis', 'Tester', 103, 3800.00,
120.00);
Output: 1 row inserted
i. Create Employee table containing all Records E_id, E_name, Age, Salary.
ii. Count number of employee names from employee table
iii. Find the Maximum age from employee table.
iv. Find the Minimum age from employee table.
v. Find salaries of employee in Ascending Order.
vi. Find grouped salaries of employees.
Output:
Table Employee created
Output:
Output:
Output:
Output:
Output:
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)
Output:
Table CUSTOMERS created.
DESC CUSTOMERS;
Output:
Name Null? Type
------- -------- -------------
ID NOT NULL NUMBER(38)
NAME VARCHAR2(100)
AGE NUMBER(38)
ADDRESS VARCHAR2(255)
SALARY NUMBER(10,2)
INSERT INTO CUSTOMERS VALUES (1, 'John Doe', 30, '123 Main St', 50000);
Output:
1 row inserted.
INSERT INTO CUSTOMERS VALUES (2, 'Jane Smith', 35, '100 WashingtonDC', 75000);
Output:
1 row inserted.
INSERT INTO CUSTOMERS VALUES (3, 'Alice', 25, '104 Sanfransisco', 75000);
Output:
1 row inserted.
Output:
Commit complete.
Output:
Output:
1 row updated.
Output:
--See the difference in output with TRIGGER and update query. RUN the following
TRIGGER first.
SET SERVEROUTPUT ON;
Output:
Output:
1 row updated.
Output:
Output:
Output:
INSERT INTO CUSTOMERS (ID, NAME, AGE, ADDRESS, SALARY) VALUES (4, 'James
Bond', 40, '121 california', 58000);
Output:
Output:
Output:
Output:
OUTPUT:
Table created
BEGIN
INSERT INTO Employee VALUES(1, 'Samarth', 30, 50000.00);
INSERT INTO Employee VALUES(2, 'Ramesh Kumar', 25, 45000.00);
INSERT INTO Employee VALUES (3, 'Seema Banu', 35, 62000.00);
INSERT INTO Employee VALUES (4, 'Dennis Anil', 28, 52000.00);
INSERT INTO Employee VALUES (5, 'Rehman Khan', 32, 58000.00);
END;
OUTPUT:
Statement Processed.
BEGIN
OPEN emp_cursor;
LOOP
FETCH emp_cursor INTO emp_id, emp_name, emp_age, emp_salary;
EXIT WHEN emp_cursor%NOTFOUND;
OUTPUT:
Procedure created.
BEGIN
fetch_employee_data;
END;
OUTPUT:
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.
Solution:
To accomplish this task in MySQL, we can use a stored procedure with
a parameterized cursor to merge data from one table
(N_RollCall) into another table (O_RollCall) while skipping existing data. We’ll
iterate through the records of N_RollCall and insert them into O_RollCall only if
they do not already exist.
Step 1: First, let’s create the N_RollCall and O_RollCall tables with similar structure:
OUTPUT:
Table created
OUTPUT:
Table created
Begin
INSERT INTO O_RollCall VALUES (1,'Shivanna','08-15-1995');
INSERT INTO O_RollCall VALUES (3,'Cheluva','12-10-1990');
end;
OUTPUT:
Statement Processed.
Begin
INSERT INTO N_RollCall VALUES(1, 'Shivanna', '08-15-1995');
INSERT INTO N_RollCall VALUES(2, 'Bhadramma','03-22-1998');
INSERT INTO N_RollCall VALUES(3, 'Cheluva', '12-10-1990');
INSERT INTO N_RollCall VALUES(4, 'Devendra', '05-18-2000');
INSERT INTO N_RollCall VALUES(5, 'Eshwar', '09-03-1997');
end;
/
OUTPUT:
Statement Processed.
OUTPUT:
Next, let’s define the merge_rollcall_data stored procedure to merge records from
N_RollCall into O_RollCall, skipping existing records:
-- Cursor declaration
CURSOR n_cursor IS
SELECT student_id, student_name, birth_date
FROM N_RollCall;
BEGIN
OUTPUT:
Procedure created.
Begin
merge_rollcall_data;
End;
OUTPUT:
Statement Processed.
7. Install an Open Source NoSQL Database MongoDB and perform basic CRUD
(Create, Read, Update and Delete) operations. Execute MongoDB basic queries
using CRUD operations.
Title: “C Programming”,
Author: “Reema Tareja”,
Category: “Programming”,
Year: 2024 },
{
Title: “Unix Programming”,
Author: “Sumitaba Das”,
Category: “Programming”,
Year: 2014 },
{
Title: “ Big Data Analytics”,
Author: “RajKamal”,
Category: “Data Science”,
Year: 2020 }]).
e. To delete:
databasename> db.collectionname.deleteOne (
{ Title: “Data Structures” } )
It deletes the document with title “Data Structures” from the database.