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’);

advertisement

delete from account where branch_name=’Downtown’;

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

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);
advertisement

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;

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;
advertisement

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.

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!

advertisement
advertisement
advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn