0% found this document useful (0 votes)
215 views3 pages

Sample Question On SQL

The document contains 15 sample questions on SQL based on different relational schemas. The questions test various SQL skills like writing queries to retrieve, update, insert and delete data from multiple tables by performing joins, aggregations and other operations.

Uploaded by

optimuz prime
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
215 views3 pages

Sample Question On SQL

The document contains 15 sample questions on SQL based on different relational schemas. The questions test various SQL skills like writing queries to retrieve, update, insert and delete data from multiple tables by performing joins, aggregations and other operations.

Uploaded by

optimuz prime
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 3

Sample Questions on SQL

The relational schema for student course registration are as follows

Parents-S(F-NID, M-NID, Sid, F-name, M-name, street, city, income)


Student (Sid, name, street, city. Mobile, email, CGPA, age, tot-cred)
Takes (course-id, Sid, semester, year, grade)
Course (course-id, title, credit-hour)
Parents-T(F-NID, M-NID, Tid, F-name, M-name, street, city, income)
Teacher (Tid, name, designation, street, city, Mobile, email, salary, date-of-birth)
Teach (course-id, Tid, semester, year, remuneration)

Q. 1: Write SQL expression to find Sid, F-NID, M-NID, mobile, email and age of all
students whose tot-cred is greater than or equal to 130.

Q. 2: Write SQL expression to find F-NID, Sid, course-id and title for all students whose
parents live in Dhaka.

Q. 3: Write SQL expression to find Sid, name, street, city and average grade of each
student.

Q. 4: Find city and street wise average, maximum and minimum income of parents (of
students) living in Dhaka or Rajshahi and average income higher than 500000.

Q. 5: Write SQL expression to find Sid, name, course-id and title of all students who have
taken any course (course-id) taken by Abid in Fall 2018.

Q. 6: Write SQL expression to find Sid, name, course-id and title of all students who have
taken all courses taken by Abid in Fall 2018.

Q. 7: Increase salary of all teachers who taught 3 credit courses by 10%.

Q. 8. Some students have become teachers. Write SQL statement to insert id, name, street,
city, mobile and email into teacher table. Other attributes will be null.

Given the relational schema as follows:

branch(branch name, branch city, assets)


customer (customer name, customer street, customer city)
loan (loan number, branch name, amount)
borrower (customer name, loan number)
account (account number, branch name, balance )
depositor (customer name, account number)
Q. 9. Write SQL for the following:

a. Insert all the loans of branch name = “NSU” to the account relation as loan number will
be account number and amount will be balance.
b. Update the database as follows: those borrower have loans more than 50000, decrease
their loan by 10%. For other borrowers, make their loan zero.
c. Delete all loans of customers who lives in ‘Gazipur’.
d. Find the list of customer name, branch name and branch city of all customers who lives
in ‘Dhaka’.
e. Find the list of customer name, branch name and branch city of all customers who have
accounts in all branch city.
f. There are some customers who have no account and also some customers who have no
loan. Find these customer name, customer street and customer city for the above using
joins.

Given the relational schema as follows:

employee (person name, street, city)


works (person name, company name, salary)
company (company name, city)

Q. 10. Write SQL for the following:


a. Find person name, street, employee.city, company name, company.city for all employees
salary greater than 10000.
b. Find person name, street and city of all employees who live in the same city as ‘Mr. Akib’
lives.
c. Find all person name of all employees who live in the same city as the company.
d. Find the list of customer name, branch name and branch city of all customers who lives in
‘Dhaka’ as per Q5.

Q11: Given relational schema as follows: 6


employee (person-name, street, city)
works (person-name, company-name, salary)
company (company-name, city)

Create a role empl with the following privileges:


Assign insert, select and delete privileges on employee relation and works relation to the
role empl. Assign select privilege on company relation to empl. There are two users e1
and e2. Now grant the above privileges to e1 and e2 using the role.

Q12: Using the relational schema of Q3, there are some employees who do not work to 6
any company. Create a view named employee-no-company with only those employees not
working to any company.

Q13: Given the following relational schema: 5


branch(branch name, branch city, assets)
customer (customer name, customer street, customer city)
borrower (customer name, loan number)
loan (loan number, branch name, amount)

Find each customer city and the total amount of loan of that customer city. Output:
customer city, loan-amount.

Q 14: Given the following relational schema: 5


branch(branch name, branch city, assets)
customer (customer name, customer street, customer city)
depositor (customer name, account number)
account (account number, branch name, balance )

a. Delete all accounts of customers who lives in ‘Sylhet’.


b. Gove 10% profit to all accounts of customers living in Bhola and 5% profit to
customers living in Dhaka and 6% to others.

Q15: Given relational schema as follows: 5


employee (person-name, street, city)
works (person-name, company-name, salary)
company (company-name, city)

Find person-name and company-name of all employees who live in the same city where
‘Abid’ lives.

You might also like