0% found this document useful (0 votes)
56 views20 pages

DBMS Queries

This document contains 3 assignments with relational database schema definitions and SQL query questions. Assignment 1 defines the SAILORS, BOATS, and RESERVES tables and includes 8 queries such as finding sailors who have reserved at least one boat and the names of sailors who have reserved red or green boats in March. Assignment 2 defines the CUSTOMER, PRODUCT, and INVOICE tables and includes 7 queries such as finding customers who have purchased more than 3 units of a product in a day and updating the CUSTOMER balance when a new invoice is added. Assignment 3 defines the DEPARTMENT, JOB, and EMPLOYEE tables and includes 6 queries such as counting employees hired in March 2015 and

Uploaded by

Samratt Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views20 pages

DBMS Queries

This document contains 3 assignments with relational database schema definitions and SQL query questions. Assignment 1 defines the SAILORS, BOATS, and RESERVES tables and includes 8 queries such as finding sailors who have reserved at least one boat and the names of sailors who have reserved red or green boats in March. Assignment 2 defines the CUSTOMER, PRODUCT, and INVOICE tables and includes 7 queries such as finding customers who have purchased more than 3 units of a product in a day and updating the CUSTOMER balance when a new invoice is added. Assignment 3 defines the DEPARTMENT, JOB, and EMPLOYEE tables and includes 6 queries such as counting employees hired in March 2015 and

Uploaded by

Samratt Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

ASSIGNMENT (1-3) QUESTION QUERIES

Q 1: Consider the following relational schema SAILORS (sid, sname, rating, date_of_birth)
BOATS (bid, bname, color) RESERVES (sid, bid, date, time slot) Write the following queries in
SQL and relational algebra
a) Find sailors who’ve reserved at least one boat
b) Find names of sailors who’ve reserved a red or a green boat in the month of March.
c) Find names of sailors who’ve reserved a red and a green boat
d) Find sid of sailors who have not reserved a boat after Jan 2018.
e) Find sailors whose rating is greater than that of all the sailors named “John”
f) Find sailors who’ve reserved all boats
g) Find name and age of the oldest sailor(s)
h) Find the age of the youngest sailor for each rating with at least 2 such sailor

A1: CREATION OF THE TABLE


INSERTING VALUES
QUERIES
Q2. Consider the following relational schema: CUSTOMER (cust_num,
cust_lname , cust_fname, cust_balance); PRODUCT (prod_num, prod_name,
price) INVOICE (inv_num, prod_num, cust_num, inv_date ,unit_sold,
inv_amount);
Write SQL queries and relational algebraic expression for the following
a) Find the names of the customer who have purchased no item. Set default value of
Cust_balance as 0 for such customers.
b) Write the trigger to update the CUST_BALANCE in the CUSTOMER table when a new
invoice record is entered for the customer.
c) Find the customers who have purchased more than three units of a product on a day. d)
Write a query to illustrate Left Outer, Right Outer and Full Outer Join.
e) Count number of products sold on each date.
f) As soon as customer balance becomes greater than Rs. 100,000, copy the customer_num in
new table called ”GOLD_CUSTOMER”
g) Add a new attribute CUST_DOB in customer table

A2: Creating tables


INSERTING VALUES
----------------------------------------------------------

QUERIES
Q 3: Consider the following relational schema
DEPARTMENT(Department_ID, Name, Location_ID)
JOB (Job_ID , Function )
EMPLOYEE (Employee_ID, name, DOB, Job_ID , Manager_ID, Hire_Date, Salary,
department_id) Answer the following queries using SQL and relational algebra:
a) Write a query to count number of employees who joined in March 2015
b) Display the Nth highest salary drawing employee details.
c) Find the budget (total salary) of each department.
d) Find the department with maximum budget.
e) Create a view to show number of employees working in Delhi and update it
automatically when the database is modified.
f) Write a trigger to ensure that no employee of age less than 25 can be inserted in the
database.
Creating tables

INSERTING VALUES
------------------------------------------------------------------------------------

--------
------------------------------------------------------------

QUERIES

You might also like