Академический Документы
Профессиональный Документы
Культура Документы
Total Marks : 20
March 6, 2019
Question 1
Which is the correct SQL command to create the table borrower having two foreign keys
customer name and loan number by using the following schemas? Primary keys are underlined
in the schemas.
Marks: 2 MCQ
• loan(loan number, branch name, amount)
1
Answer: a)
In option b) only customer name is declared as PRIMARY KEY, but in the given schema
borrower there are two attributes namely customer name and loan number which are PRIMARY
KEY well as FOREIGN KEY.
Option c) generates an error message as table can have only one primary key. To de-
clare two columns as PRIMARY KEY we must use PRIMARY KEY(column1, column2) in the
CREATE TABLE command.
Option d) generates an error message missing keyword, since REFERENCES keyword is missed
for the FOREIGN KEY(customer name).
So from the above options only option a) is correct and rest are incorrect.
2
Question 2
Identify the correct INSERT command/s to create a record for the customer table as given
below. Primary key is underlined in the schema.
Marks: 2 MSQ
customer
customer name customer street customer city
Answer: a), d)
Or
Option b) generates an error message as character values must use (’ ’) single quote.
3
Question 3
Choose the correct SQL command to display the customer name and loan number of customers
who have a loan from bank and whose name starts with ’A’. Primary keys are underlined in
the schema.
Marks: 2 MCQ
Answer: b)
Explanation:
To search for a specified pattern in a column we use LIKE operator in the WHERE clause. The
% sign represent zero or multiple characters.
Option a) displays the name and loan number of customers whose names are exactly ’A’.
Option c) displays the name and loan number of customers whose names ends with ’A’.
Option d) gives error message, invalid relational operator for the word LIKES.
4
Question 4
Which of the following option/s is/are correct to find the names of the customers who are
having account in the bank without having a loan in the bank? Primary keys are underlined
in the schemas.
Marks: 2 MSQ
b) SELECT customer_name
FROM depositor
WHERE customer_name
NOT IN
(SELECT customer_name
FROM borrower);
c) SELECT customer_name
FROM borrower
WHERE customer_name
NOT IN
(SELECT customer_name
FROM depositor);
Answer: b), d)
Explanation: We can use NOT IN or MINUS or EXCEPT operators to solve this type of query.
Option a) finds the names of the customers who have both an account and a loan in the
bank.
Option c) finds the names of the customers who have a loan but do not have an account
in the bank.
5
Question 5
Consider the schemas person and salary to identify the correct query/queries that display/s
the name and the salary of the persons who work in ‘KOLKATA’. Primary keys are underlined
in the schemas. Marks: 2 MSQ
Answer: c), d)
Explanation: From the above option c) and d) are correct as it uses join operation to
compare the attributes person.person id and salary.person id to avoid ambiguity in the
columns.
SELECT columns
FROM table1 JOIN table2
ON table1.column = table2.column;
Option b) perform Cartesian products between person and salary which will not compare
for the equality of column values.
6
Question 6
Which is/are the correct SQL command/s to display the loan numbers of the customers in
ascending order of their loan amounts. Primary key is underlined in the schemas.
Marks: 2 MSQ
Answer: a), c)
Explanation: The ORDER BY clause is used to sort list items in ascending order by de-
fault. We also use DSC or ASC to sort the values in descending or ascending order respectively.
Option b) and d) are incorrect since option b) generates the error message, SQL command
not properly ended since SORT BY is not valid for this.
7
Question 7
Given the schema (primary key is underlined) Marks: 2 MCQ
c) Finds the salary of all persons having less than the highest salary
Answer: b)
Explanation:
This is a SUB-QUERY in SQL which finds the maximum salary from the table and then com-
pares the salary which is less than the maximum salary to find the second highest salary.
8
Question 8
Suppose a bank wants to make a view consisting of the names of customers having loan in
’MUMBAI’ branch with the loan amount being more than 50000 but less than 70000. Identify
the correct query from the following. Primary keys are underlined in the schemas.
Marks: 2 MSQ
a) CREATE VIEW v1 AS
SELECT customer_name
FROM loan, borrower
WHERE branch_name = ’MUMBAI’
AND loan.loan_number = borrower.loan_number
AND amount > 50000 AND amount < 70000;
b) CREATE VIEW v1 AS
SELECT customer_name
FROM loan
WHERE branch_name = ’MUMBAI’
AND amount > 50000 AND amount < 70000;
c) CREATE VIEW v1 AS
SELECT customer_name
FROM loan, borrower
WHERE branch_name = ’MUMBAI’
AND loan.loan_number = borrower.loan_number
AND amount BETWEEN 50000 AND 70000;
d) CREATE VIEW v1 AS
SELECT customer_name
FROM loan, borrower
WHERE branch_name = ’MUMBAI’
AND amount > 50000, amount < 70000;
Answer: a), c)
Option b) generates error,"CUSTOMER NAME": invalid identifier since borrower table is miss-
ing in the FROM clause.
Option d) also generates error – SQL command not properly ended since the conditions
are combined through (,) instead of AND operator.
9
Question 9
Identify the following the correct way/s to delete all rows at a time from salary table.
Marks: 2 MSQ
Answer: b), c)
Explanation: To delete all rows from a table we can use either DELETE or TRUNCATE command
and the syntax for these commands are:
and
So option b) and c) are correct and rest of the options are incorrect.
10
Question 10
Find the names of the branches whose average loan amount is more than 70000. Primary keys
are underlined in the schemas.
Marks: 2 MCQ
a) SELECT branch_name
FROM loan
GROUP BY branch_name AVG(amount) > 70000;
b) SELECT branch_name
FROM loan
GROUP BY branch_name
HAVING AVG(amount) > 70000;
c) SELECT branch_name
FROM loan
ORDER BY branch_name
HAVING AVG(amount) > 70000;
d) SELECT branch_name
FROM loan
GROUP BY branch_name
HAVING amount > 70000;
Answer: b)
So only option b) is correct and rest of the options are all incorrect.
Option a) generates error – SQL command not properly ended due to missing of HAVING
clause.
Option c) is also gives the error – SQL command not properly ended as it uses ORDER BY
clause before HAVING
Option d) does not compare the average loan amount since AVG keyword is missing.
11