LAB Set Questions Rdbms
LAB Set Questions Rdbms
a) Create a database table BANK, add constraints (primary key, unique, check, Not null)
i) Insert 10 rows – insert the values in sql prompt;
ii) Update the column balance of ACCNO - 101 to 50000
iii) Delete the row where balance is greater the 1000000
iv). Create a view for the above data and display it.
i) Create Student table Course table and Registration table with the fields as shown above.
ii) Implement the Keys as shown in the diagram.
iii) Display the student's first name alone with the course name that they have registered.
-- Displaying student's first name with the course name they have registered for
SELECT s.FirstName, c.CourseName
FROM Student s
JOIN Registration r ON s.StudentID = r.StudentID
JOIN Course c ON r.CourseID = c.CourseID;
6. a) i) Create table person with following fields - person ID, Name age with primary key not null
constraint
1. List the E_no, E_name, Salary of all employees working for MANAGER.
5. List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.
FROM EMPLOYEE
SELECT *
FROM EMPLOYEE
SELECT *
FROM EMPLOYEE
SELECT E_name
FROM EMPLOYEE
SELECT *
FROM EMPLOYEE
ii) Create table order with following attributes ordered, productid, and quantity unitprice.
-- Create table order
CREATE TABLE order_table (
ordered INT,
productid INT,
quantity INT,
unitprice DECIMAL(18, 2));
-- Insert 5 rows into the order table
INSERT INTO order_table (ordered, productid, quantity, unitprice)
VALUES
(1, 1, 100, 10.00),
(2, 2, 250, 15.00),
(3, 3, 180, 12.00),
(4, 4, 300, 20.00),
(5, 5, 150, 8.00);
iii) Write a sub query to display the records from product table whose product id matches with
product id in order table with quantity greater than 200.
SELECT *
FROM product
WHERE productid IN (
SELECT productid
FROM order
WHERE quantity > 200);
-- Increment salary
new_salary := new_salary + amount;
DECLARE
updated_salary DECIMAL(18, 2);
BEGIN
updated_salary := IncrementSalary(1, 1000); -- Increment salary of EmployeeID 1 by 1000
DBMS_OUTPUT.PUT_LINE('New Salary: ' || updated_salary);
END;
/
11) Create PL SQL function to calculate tax
12) Create an employee table and write PL SQL function to calculate experience of the
employee.
-- Calculate experience in years (assuming the current date is used as the end date)
emp_experience := TRUNC(MONTHS_BETWEEN(SYSDATE, emp_start_date) / 12);