Bcs403 Manual
Bcs403 Manual
--Check that the records were rolled back (should return 0 rows)
SELECT *FROM Employee;
Step 5: Insert null values to the employee table and verify the result:
---- Attempt to insert a record with a NULL value in a NOT NULL column (ENAME)
INSERT INTO VALUES (4, NULL, 'Tester', 2, 3000, 200);
-- This insert will fail due to the NOT NULL constraint on ENAME
Prog 2. Create a table called Employee that contains the following attributes.
Employee (EMPNO, ENAME, JOB, MGR, SALARY) and execute the
following
INSERT INTO Employee VALUES (101, 'Raj Kumar', 'Manager', NULL, 80000, 5000);
INSERT INTO Employee VALUES (102, 'Shiva Kumar', 'Analyst', 101, 60000, 3000);
INSERT INTO Employee VALUES (103, 'Arun Kashyap', 'Clerk', 102, 40000, 1000);
INSERT INTO Employee VALUES (104, 'Ravi Gowda', 'Sales Executive', 101, 70000, 4000);
INSERT INTO Employee VALUES (105, 'Anand Yadav', 'Clerk', 102, 38000, 800);
UPDATE Employee
SET JOB = 'Senior Manager'
WHERE EMPNO = 101;
UPDATE Employee
SET JOB = 'Senior Analyst'
WHERE EMPNO = 102;
UPDATE Employee
SET JOB = 'Office Clerk'
WHERE EMPNO = 105;
UPDATE Employee
SET JOB = 'Sales Manager'
WHERE EMPNO = 104;
Prog 3. Queries using aggregate functions (COUNT, AVG, MIN, MAX, SUM),
Group by, Orderby. Employee (E_id, E_name, Age, Salary)
Create Employee table containing all Records E_id, E_name, Age, Salary.
Count number of employee names from employee table.
Find the Maximum age from employee table.
Find the Minimum age from employee table.
Find salaries of employee in Ascending Order.
Find grouped salaries of employees.
STEP 3: Count the number of employee names from the employee table
Prog 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)
STEP 3: Test the Trigger: Now, perform INSERT, UPDATE, and DELETE operations on the
CUSTOMERS table to see the trigger in action.
Insert Operation:
Update Operation:
UPDATE CUSTOMERS
SET SALARY = 6000
WHERE ID = 1;
Delete Operation:
Prog 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)
STEP 1: Create the Employee Table
v_E_id Employee.E_id%TYPE;
v_E_name Employee.E_name%TYPE;
v_Age Employee.Age%TYPE;
v_Salary Employee.Salary%TYPE;
CURSOR employee_cursor IS
SELECT E_id, E_name, Age, Salary FROM Employee;
BEGIN
OPEN employee_cursor;
LOOP
FETCH employee_cursor INTO v_E_id, v_E_name, v_Age, v_Salary;
DBMS_OUTPUT.PUT_LINE('E_id: ' || v_E_id || ', E_name: ' || v_E_name || ', Age: ' ||
v_Age || ', Salary: ' || v_Salary);
END LOOP;
CLOSE employee_cursor;
END;
/
Prog 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.
DECLARE
v_n_rollcall_id N_RollCall.id%TYPE;
v_n_rollcall_name N_RollCall.name%TYPE;
v_n_rollcall_date N_RollCall.roll_date%TYPE;
CURSOR c_merge_rollcall_data IS
SELECT id, name, roll_date
FROM N_RollCall nrc
WHERE NOT EXISTS (
SELECT 1
FROM O_RollCall orc
WHERE orc.id = nrc.id
AND orc.name = nrc.name
AND orc.roll_date = nrc.roll_date
);
BEGIN
OPEN c_merge_rollcall_data;
LOOP
FETCH c_merge_rollcall_data INTO v_n_rollcall_id, v_n_rollcall_name,
v_n_rollcall_date;
EXIT WHEN c_merge_rollcall_data%NOTFOUND;
CLOSE c_merge_rollcall_data;
COMMIT;
Prog 7. Install an Open Source NoSQL Data base MongoDB & perform basic
CRUD (Create, Read, Update& Delete) operations. Execute MongoDB basic
queries using CRUD operations.
Performing Basic CRUD Operations:
1. Create Operation:
use basictask;
2. Insert Operation:
a) Insert single documents:
db.users.insertOne({
name: "Braham Kumar",
age: 25,
email: "[email protected]",
status: "inactive"
});
3. Read Query:
a) Find all documents:
db.users.find();
OUTPUT
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf6'),
name: 'Braham Kumar',
age: 25,
email: '[email protected]',
status: 'inactive'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
age: 35,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
name: 'Bikash Singh',
age: 28,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf9'),
name: 'Shoaib Akhtar',
age: 28,
email: '[email protected]',
status: 'active'
}
]
3. Read Query:
b) Find documents with specific criteria (example: find all users with age greater than 25):
db.users.find({ age: { $gt: 25 } });
OUTPUT
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
age: 35,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf8'),
name: 'Bikash Singh',
age: 28,
email: '[email protected]',
status: 'active'
},
{
_id: ObjectId('666c78f13c52fc36f3cdcdf9'),
name: 'Shoaib Akhtar',
age: 28,
email: '[email protected]',
status: 'active'
}
]
OUTPUT
4. Update Query:
db.users.updateOne(
{ $set: { age: 31 } }
);
OUTPUT
[
{
_id: ObjectId('666c78f13c52fc36f3cdcdf7'),
name: 'Shubham Kumar',
age: 35,
email: '[email protected]',
status: 'active'
}
]
db.users.updateMany(
{ age: { $gt: 28 } },
{ $set: { status: "inactive" } }
);
db.users.find({ age: { $gt: 28 } });
5. Delete Query:
Basic Queries:
db.users.count();
b) Sorting documents:
db.users.find().limit(5);
db.users.aggregate([
{ $group: { _id: "$age", count: { $sum: 1 } } }
]);