RDBMS Questions and Answers – SQL Queries – II

This set of RDBMS Questions and Answers for Campus interviews focuses on “Sql Queries – II”.

1. Delete the accounts and loans of Downtown branch.
View Answer

Answer: delete from depositor where account_number IN
(select account_number from account where branch_name=’Downtown’);

delete from account where branch_name=’Downtown’;

delete from borrower where loan_number IN
(select loan_number from loan where branch_name=’Downtown’);

advertisement
advertisement

delete from loan where branch_name=’Downtown’;

2. Add a column phoneNo to customer table.
View Answer

Answer: alter table customer add phoneNo numeric(10);
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

3. Change the size of the branch_city to varchar(20).
View Answer

Answer: ALTER TABLE branch ALTER COLUMN branch_city type varchar(20);

4. Drop the column phoneNo from customer table.
View Answer

Answer: ALTER TABLE customer drop phoneNo;
advertisement

5. For all customers who have a loan from the bank, find their names, loan numbers, and loan amount.
View Answer

Answer: select customer_name,loan_number,amount from borrower
natural join loan;

6. Find the customer names, loan numbers, and loan amounts, for all loans at the Perryridge branch.
View Answer

Answer: select customer_name,loan_number,amount from depositor
natural join loan where loan.branch_name=’Perryridge’;
advertisement

7. For all customers who have a loan from the bank, find their names and loan numbers with the attribute loan_number replaced by loan_id.
View Answer

Answer: select customer_name,loan_number as loan_id,amount from depositor
natural join loan;

8. Find the names of all branches that have assets greater than atleast one branch located in Brooklyn.
View Answer

Answer: select branch_name from branch where assets >
(select min(assets) from branch where branch_city = ‘Brooklyn’);

9. Find the names of all customers whose street address includes the substring ‘Main’.
View Answer

Answer: select customer_name from customer where customer_street
like ‘%Main%’;

10. List loan data, ordered by decreasing amounts, then increasing loan numbers.
View Answer

Answer: select * from loan order by amount desc, loan_number asc;

Sanfoundry Global Education & Learning Series – RDBMS.

To practice all areas of RDBMS for Campus Interviews, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.