DBMS_Lab QBank (1)
DBMS_Lab QBank (1)
SQL operations.
Answer:
USE XYZ;
Salary INT,
Date_of_joining DATE,
Dept_no INT,
);
(1,"A",250000,'2019-03-23',203,"Developer"),
(2,"B",250000,'2019-01-20',203,"Developer"),
(3,"C",270000,'2015-09-02',201,"Management"),
(4,"D",200000,'2020-08-24',202,"Testing"),
(5,"E",260000,'2015-12-24',203,"Developer"),
(6,"F",230000,'2018-03-11',203,"Developer"),
(7,"G",180000,'2023-02-04',202,"Testing"),
(8,"H",150000,'2021-10-21',202,"Testing"),
(9,"I",220000,'2021-09-27',201,"Management"),
(10,"J",190000,'2022-05-17',201,"Management");
FROM employee;
UPDATE emp_v1
WHERE emp_id=9;
ON employee (e_name);
----------------------------------------------------------------------------------------
2) Consider the relation employee (emp_id, e_name, salary, Date_of_joining, Dept_no, Designation) perform basic
SQL operations.
Answer :
USE XYZ;
CREATE TABLE employee(
e_name VARCHAR(50),
Salary INT,
Date_of_joining DATE,
Dept_no INT,
Designation VARCHAR(20)
);
(1,"A",250000,'2019-03-23',203,"Developer"),
(2,"B",250000,'2019-01-20',203,"Developer"),
(3,"C",270000,'2015-09-02',201,"Management"),
(4,"D",200000,'2020-08-24',202,"Testing"),
(5,"E",260000,'2015-12-24',203,"Developer"),
(6,"F",230000,'2018-03-11',203,"Developer"),
(7,"G",380000,'2023-02-04',200,"Counceller"),
(8,"H",150000,'2021-10-21',202,"Testing"),
(9,"I",220000,'2021-09-27',201,"Marketing"),
(10,"J",190000,'2022-05-17',201,"Management");
SET SQL_SAFE_UPDATES = 0;
UPDATE employee
SET city="Mumbai";
SET city="Pune"
WHERE Designation="Counceller";
UPDATE employee
SET city="Banglore"
WHERE Designation="Testing";
SELECT Designation
FROM employee
GROUP BY Designation;
FROM employee
WHERE City="Mumbai";
FROM employee
SELECT Designation
FROM employee
GROUP BY Designation
HAVING COUNT(emp_id)>1;
RENAME TO emp1;
----------------------------------------------------------------------------------------
3)Consider the relation employee (emp_id, e_name, salary, Date of Joining, Dept_no, Designation) perform basic
SQL operations.
Answer:
USE XYZ;
e_name VARCHAR(50),
Salary INT,
Date_of_joining DATE,
Dept_no INT,
Designation VARCHAR(20)
);
(1,"A",250000,'2009-03-23',203,"Developer"),
(2,"B",250000,'2009-01-20',203,"Developer"),
(3,"C",270000,'2005-09-02',201,"Management"),
(4,"D",200000,'2000-08-24',202,"Testing"),
(5,"E",260000,'2005-12-24',203,"Developer"),
(6,"F",230000,'2008-03-11',203,"Developer"),
(7,"G",380000,'2003-02-04',200,"Counceller"),
(8,"H",150000,'2001-10-21',202,"Testing"),
(9,"I",220000,'2011-09-27',204,"Marketing"),
(10,"J",190000,'2012-05-17',201,"Management");
FROM employee
GROUP BY Dept_no
LIMIT 1;
FROM employee
SELECT
FROM employee;
SELECT *
FROM employee
WHERE salary<(
SELECT AVG(salary)
FROM employee
WHERE Dept_no=203
);
SELECT *
FROM employee
FROM employee
SELECT *
FROM employee
WHERE MONTH(Date_of_joining)=8;
SELECT *
FROM employee
FROM employee
GROUP BY Dept_no;
----------------------------------------------------------------------------------------
4)Consider two tables Customer(c_id, c_name , email , city , pincode)Order(order_id , date , amount , cust_id.
1. Create both the tables with primary key and foreign key constraints.
2. insert 10 records each.
3. Find all orders placed by customers with cust_id 2
4. Find list of customers who placed their order and details of order
5. List of customers who haven’t placed order
6. List all orders and append to customer table
7. Display all records
8. Display customer that are from same city 8
Answer:
USE XYZ;
email VARCHAR(50),
city VARCHAR(20),
pincode INT
);
order_date DATE,
amount INT,
cust_id INT,
);
WHERE cust_id=2;
SELECT *
FROM customer
SELECT *
FROM customer
SELECT *
FROM customer
c2.c_name AS customer2_name,
c1.city
FROM customer c1
SELECT *
FROM borrower
LEFT JOIN fine ON borrower.rollno=fine.roll_no;
----------------------------------------------------------------------------------------
6) Consider student (roll_no, name, marks, class) table. Column roll_no is primary key. Perform any 3 DLL and any
3 DML operations on the table.
Answer:
USE XYZ;
name VARCHAR(50),
marks INT,
class VARCHAR(10)
);
(1,"A",11,"10",16),
(2,"B",17,"10",16),
(3,"C",14,"10",16);
ALTER TABLE student
UPDATE student
SET marks=15
WHERE roll_no=3;
WHERE marks<15;
RENAME TO stud_info;
----------------------------------------------------------------------------------------
7) Write a SQL statement to create a table job_history including columns employee_id, start_date, end_date, job_id
and department_id and make sure that, the employee_id column does not contain any duplicate value at the time of
insertion and the foreign key column job_id contain only those values which are exists in the jobs table . Consider
table Job (job_id,job_title.min_sal,max_sal)
Answer:
end_date DATE,
department_id INT,
UNIQUE (employee_id),
);
----------------------------------------------------------------------------------------
USE XYZ;
street VARCHAR(100),
city VARCHAR(50)
);
employee_name VARCHAR(50),
company_name VARCHAR(50),
salary INT,
);
city VARCHAR(50)
);
manager_name VARCHAR(50),
);
FROM employee e
SELECT e.employee_name
FROM employee e
SELECT w.employee_name
FROM works w
JOIN (
FROM works
GROUP BY company_name
----------------------------------------------------------------------------------------
10) Implement CRUD operations. SAVE method. Use following Collection. Perform Map Reduce to count quantity
of each item.
Item: Item ID, Item quantity, price, brand.
13) Implement Map reduces operation for counting the marks of students.
14) Implement Map reduces operation for displaying persons with same profession.
1.Create Collection.
17) Consider student ( roll_no, name ,marks, class) table. Perform add update and delete operation on same table
through java program. Write menu driven program.
18) Implement Stored Procedure namely proc_Grade for the categorization of student. If marks scored by students in
examination is <=1500 and marks>=990 then student will be placed in distinction category if marks scored are
between 989 and900 category is first class, if marks 899 and 825 category is Higher Second Class. Write a PL/SQL
block for using procedure created with above requirement. Stud_Marks(name, total_marks) Result(Roll,Name,
Class).
19) Write a database trigger on customer( cust_id, c_name, addr) table. The System should keep track of the records
that are being updated or deleted. The old value of updated or deleted records should be added in cust_Audit table.
20) Implement a database trigger on client_master( c_id, c_name, acc_no) table. The System should keep track of
the records that are being updated or inserted. The old value of updated or deleted records should be added in
client_Audit table.
21) Implement a PL/SQL block of code using explicit 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.
22) Write a PL/SQL block of code for the following requirements:- Schema: Borrower(Rollin, Name, DateofIssue,
NameofBook, Status) 2. Fine(Roll_no,Date,Amt) Accept roll_no & name of book from user. Check the number
of days (from date of issue), if days are between 15 to 30 then fine amount will be Rs 5per day. If condition of fine
is true, then details will be stored into fine table.
3. Create a view emp_vl of table employee which has emp_id , name and dept-attributes.
4. Display name and department of employee working in Manager or Marketing department
5. Display employees who were hired earliest or latest.
6. Display name and department no of employees who are manager, market analysts. Use
Predicates
d. truncate table.
e. find list of customers who placed order and details of their orders.