Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Federal Urdu University of Arts, Science and Technology,

Islamabad
Department of Computer Science
Final-Term Examination Fall 2020

Advanced Database Systems (ADBS) Wednesday 17 Feb, 2021


Mr. Furqan Shahid BS(CS) 4 A&B Morning
Duration: 6 Hours (09:30 AM to 03:30 PM) Total Marks: 50

Q 1. 7 marks
Write SQL statements for the followings:
a) Create the table: Sales(Sr_no, Date_time, Customer_cnic,
No_of_items, Total_amount)
Constaints:
 "Sr_no" is the primary key
 At least one item must be present for each sale
 "Customer_cinc" is the foreign key (the parent key in the
"Customer" table)
b) Insert new "sale records" using the substitution variables
c) Delete those "sale records" which are one month (or more) old
Q 2.
Let we have following table: TabX(x1, x2, x3); Write SQL commands for 14 marks
followings:
a) Add column "x4"; where, "x4" can store floating point data
b) Remove the column "x2"
c) The default value for column "x3" is "5"
d) Change data type of column "x1"; The new data type is
"varchar(20)"
e) Make "x1" unique and nullable
f) Make "x4" unique and "not null"
g) Remove the default value of column "x1"
Q 3. 12 marks
Write following queries on "employees" table (in HR schema):
a) Display records sorted w.r.t “salary” in descending order;
furthermore, "hire_date" should follow this format "17 Feb,
2020 Wed"
b) Display the second highest salary
c) Display records of the employees who have the second highest
salary

Page 1|2
d) Display total number of employees and total salary
e) Display department-wise total number of employees and total
salary (i.e. "total salary" and "total number of employees" in
each department)
f) Display records of those departments in which total salary of
employees is greater or equal 10,000
Q 4. 3 marks
Create self-join for the following table:
Account (Acc_no, Acc_title, Opening_date, Acc_value,
Introducer_Acc_no)
Hint: Acc_no is the parent key; Introducer_Acc_no is the child key
Q 5. 14 marks
Write PL/SQL codes for:
a) Print "sum" and "product" of all odd numbers between "n1" and
"n2", where, "n1" and "n2" are the parameters.
b) Fetch and display records of those "Accounts" which title begins
with the letter "J". (“Accounts” table given in Q#4)
c) Create trigger to store deleted account records in the table
"Closed_accounts".
d) Create trigger to automatically assign value to the column
"Acc_value" at the time of insertion. Criteria is as under:
 If Acc_title begins with letter "I": Acc_value = 1000;
 If Acc_title begins with letter "J": Acc_value = 10000;
 If Acc_title begins with letter "B": Acc_value = 50000;
 If Acc_title begins with letter "V": Acc_value = 100000;

Good Luck

Page 2|2

You might also like