Books Isbn - N o Title Publisher - I D Year
Books Isbn - N o Title Publisher - I D Year
1. Books
2. Authors
3. Publishers
4. WrittenBy
isbn_n author_id
o
123456 1
654321 2
112233 3
444555 4
678901 10
678901 1
1. Products
2. Customers
3. Orders
Worker Table
Bonus Table
WORKER_REF_ID BONUS_AMOUNT BONUS_DATE
1 5000 2021-06-01
2 7000 2023-01-01
3 3000 2022-09-01
Title Table
2 Senior 2020-01-01
Manager
4 Manager 2022-08-01
1. Write an SQL query to fetch “FIRST_NAME” from Worker table using the alias name as
<WORKER_NAME>
3. Write an SQL query to print all Worker details from the Worker table order by
FIRST_NAME Ascending.
Output:
4. Write an SQL query to print details of the Workers whose FIRST_NAME ends
with ‘h’ and contains six alphabets.
6. Write an SQL query to fetch departments along with the total salaries paid for
each of them.
7. Write an SQL query to fetch the names of workers who earn the highest salary.
DECLARE
avg_value NUMBER;
BEGIN
-- Call the function with example values
avg_value := calculate_average(10, 20, 30);
Output:
5)[28/07/2023]
Consider the following employee database, primary keys are
underlined :
employee (employee-name, street, city)
works (employee-name, company-name, salary)
company (company-name, city)
manages (employee-name, manager_name)
Give an expression in SQL for each of the following queries:
1. Find the names of all employees who work for First Bank
Corporation.
SELECT employee-name
FROM works
WHERE company-name = 'First Bank Corporation';
Output:
3. Find the names and cities of residence of all employees who work
for First Bank Corporation.
6. Find all employees in the database who do not work for First Bank
Corporation.
SELECT e.employee-name
FROM employee e
WHERE e.employee-name NOT IN (
SELECT w.employee-name
FROM works w
WHERE w.company-name = 'First Bank Corporation'
);
Output:
6)[15/07/2022]
Consider Following 3 Tables for library database and Write SQL Queries.
1. Books ( BookID, BookTitle, Price, Author, Publisher )
2. Students (StudID, StudName, DOB, Gender, Branch, Sem, Address)
3. Issue_Books ( StudID, BookID, Issue_Date)
1: List all Books whose Title contains word ‘DBMS’.
2: Display all Publisher Name & Total Price of Books of that publisher.
3: Display list of all books which are not issued to any students.
4. Display the author name whose number of books is maximum in library.
5: Display all Books assigned to student with name “RAJESH”.
7)[04/03/2021]
TABLE Worker(WORKER_ID INT NOT NULL PRIMARY KEY,FIRST_NAME CHAR(25), LAST_NAME
CHAR(25),SALARY INT(15),JOINING_DATE DATETIME,DEPARTMENT CHAR(25));
TABLE Bonus(WORKER_REF_ID INT,BONUS_AMOUNT INT(10),BONUS_DATE DATETIME,FOREIGN
KEY (WORKER_REF_ID),REFERENCES Worker(WORKER_ID));
TABLE Title(WORKER_REF_ID INT,WORKER_TITLE CHAR(25),AFFECTED_FROM
DATETIME,FOREIGN KEY (WORKER_REF_ID)REFERENCES Worker(WORKER_ID));
Consider above 3 tables ,assume appropriate data and solve following SQL queries
1. Find out unique values of DEPARTMENT from Worker table
2. Print details of the Workers whose SALARY lies between 100000 and 500000.
3. Print details of the Workers who have joined in Feb’2014.
4. Fetch worker names with salaries >= 50000 and <= 100000.
8) [04/03/2021]
TABLE Worker(WORKER_ID INT NOT NULL PRIMARY KEY,FIRST_NAME CHAR(25), LAST_NAME
CHAR(25),SALARY INT(15),JOINING_DATE DATETIME,DEPARTMENT CHAR(25));
TABLE Bonus(WORKER_REF_ID INT,BONUS_AMOUNT INT(10),BONUS_DATE DATETIME,FOREIGN
KEY (WORKER_REF_ID),REFERENCES Worker(WORKER_ID));
TABLE Title(WORKER_REF_ID INT,WORKER_TITLE CHAR(25), AFFECTED_FROM
DATETIME,FOREIGN KEY (WORKER_REF_ID)REFERENCES Worker(WORKER_ID));
Consider above 3 tables ,assume appropriate data and solve following SQL queries
1. Print details of the Workers who are also Managers.
2. SQL query to clone a new table from another table.
3. Fetch the list of employees with the same salary.
4. Fetch “FIRST_NAME” from Worker table in upper case.
9)[11/09/2021]
Consider the following relations and write SQL queries for given
statements. Assume suitable constraints.
job(job-id, job-title, minimum-salary, maximum-salary)
employee(emp-no, emp-name, emp-salary,dept-no)
deposit(acc-no, cust-name, branch-name, amount, account-date)
borrow(loan-no, cust-name, branch-name, amount)
department (dept-no, dept-name)
job Table
employee Table
borrow Table
deposit Table
department Table
dept-no dept-name
1 Finance
2 HR
3 IT
Output:
2. Give name of depositors whose branch name starts from ‘S’.
SELECT cust-name
FROM deposit
WHERE branch-name LIKE 'S%';
Output:
SELECT e.emp-name
FROM employee e
JOIN department d ON e.dept-no = d.dept-no
WHERE e.emp-salary BETWEEN 20000 AND 30000 AND d.dept-name = 'Finance';
Output:
UPDATE employee
SET emp-salary = emp-salary * 1.10
WHERE dept-no = (SELECT dept-no FROM department WHERE dept-name = 'Finance');
Output:
10) [11/09/2021]
Write a PL/SQL program that fetches records of all students and insert
record as students having CPI > 4 in ELIGIBLE table and students having
CPI <= 4 in NOT_ELIGIBLE table from student_master table.
DECLARE
CURSOR student_cursor IS
SELECT student_id, student_name, CPI
FROM student_master;
v_student_id student_master.student_id%TYPE;
v_student_name student_master.student_name%TYPE;
v_CPI student_master.CPI%TYPE;
BEGIN
FOR student_record IN student_cursor LOOP
v_student_id := student_record.student_id;
v_student_name := student_record.student_name;
v_CPI := student_record.CPI;
EXCEPTION
WHEN OTHERS THEN
-- Handle exceptions and rollback
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('Error occurred: ' || SQLERRM);
END;
/
11)[29/10/2020]
Write a PL/SQL block to print the given number is odd or even.
DECLARE
num INTEGER := 15; -- You can change this number to check different values
BEGIN
IF MOD(num, 2) = 0 THEN
DBMS_OUTPUT.PUT_LINE(num || ' is an even number.');
ELSE
DBMS_OUTPUT.PUT_LINE(num || ' is an odd number.');
END IF;
END;
/
Output:
12)[29/10/2020]
Consider the following relational schemas:
EMPLOYEE (EMPLOYEE_NAME, STREET, CITY)
WORKS (EMPLOYEE_NAME, COMPANYNAME, SALARY)
COMPANY (COMPANY_NAME, CITY) Give an expression in SQL for each of queries below:
1. Specify the table definitions in SQL.
2. Find the names of all employees who work for first Bank Corporation.
3. Find the names and company names of all employees sorted in ascending order of company
name and descending order of employee names of that company.
4. Change the city of First Bank Corporation to ‘New Delhi’.
13)[29/10/2020]
Write a PL/SQL block to print the sum of even numbers from 1 to 50.
DECLARE
sum_even NUMBER := 0; -- Variable to hold the sum of even numbers
BEGIN
FOR i IN 1 .. 50 LOOP
IF MOD(i, 2) = 0 THEN -- Check if the number is even
sum_even := sum_even + i; -- Add even number to the sum
END IF;
END LOOP;
Output:
14)[29/10/2020]
Given the following relations
TRAIN (NAME, START, DEST)
TICKET (PNRNO., START, DEST, FARE)
PASSENGER (NAME, ADDRESS, PNRNO.)
Write SQL expressions for the following queries: Note: Assume NAME of Train is a column of
Ticket.
1. List the names of passengers who are travelling from the start to the destination station of
the train.
2. List the names of passengers who have a return journey ticket.
3. Insert a new Shatabti train from Delhi to Bangalore.
4. Cancel the ticket of Tintin.
15)[07/06/2019]
Write a PL/SQL block to print the sum of Numbers from 1 to 100.
DECLARE
sum_total NUMBER := 0; -- Variable to hold the sum
BEGIN
FOR i IN 1 .. 100 LOOP
sum_total := sum_total + i; -- Add the current number to the sum
END LOOP;
Output:
16)[07/06/2019]
Write a PL/SQL block to print the given number is prime or not.
DECLARE
num INTEGER := 29; -- You can change this number to check different values
is_prime BOOLEAN := TRUE;
BEGIN
IF num <= 1 THEN
is_prime := FALSE;
ELSE
FOR i IN 2 .. TRUNC(SQRT(num)) LOOP
IF MOD(num, i) = 0 THEN
is_prime := FALSE;
EXIT; -- Exit loop if a divisor is found
END IF;
END LOOP;
END IF;
IF is_prime THEN
DBMS_OUTPUT.PUT_LINE(num || ' is a prime number.');
ELSE
DBMS_OUTPUT.PUT_LINE(num || ' is not a prime number.');
END IF;
END;
/
Output:
17)[30/11/2019]
Consider following schema and write SQL for given statements.
Student (RollNo, Name, DeptCode, City)
Department (DeptCode, DeptName) Result (RollNo, Semester, SPI)
1. Display the name of students with RollNo whose name ends with ‘sh’.
2. Display department wise total students whose total students are greater than 500.
3. List out the RollNo, Name along with CPI of Student.
4. Create RollNo field as primary key for existing Student table.
5. Display student name who got highest SPI in semester 1.
6. Display the list of students whose DeptCode is 5, 6,7,10.
7. Create table Student_New from student table without data.
18)[30/11/2019]
Consider the tables given below. Write the SQL queries for the questions given below:
T1 ( Empno, Ename , Salary, Designation,)
T2 (Empno, Deptno.)
1. 1.Display all the details of the employee whose salary is lesser than 10000.
2. 2.Display the Deptno in which Employees with name starting with letter ‘S’ is working.
3. 3.Add a new column Deptname in table T2.
4. 4.Change the designation of Geeta from ‘Manager’ to ‘Senior Manager’.
5. Find the total salary of all the employees department wise.
6. 6.Add Empno as primary key in existing table T1.
7. 7.Display the Deptno having highest number of employees.