The document describes a database schema for a banking enterprise with tables for branches, accounts, customers, deposits, loans, and borrowers. It includes examples of:
1) Creating the tables and specifying primary and foreign keys
2) Inserting sample data into each table
3) A query to find customers with over 1 account at a specific branch
4) A query to find customers with accounts at all branches in a city
5) A query to delete account records at branches in a specific city
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
172 views
Dbms Lab
The document describes a database schema for a banking enterprise with tables for branches, accounts, customers, deposits, loans, and borrowers. It includes examples of:
1) Creating the tables and specifying primary and foreign keys
2) Inserting sample data into each table
3) A query to find customers with over 1 account at a specific branch
4) A query to find customers with accounts at all branches in a city
5) A query to delete account records at branches in a specific city
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3
5.
Consider the following database for a banking enterprise:
BRANCH(branch-name:string, branch-city:string, assets:real) ACCOUNT(accno:int, branch-name:string, balance:real) DEPOSITOR(customer-name:string, accno:int) CUSTOMER(customer-name:string, customer-street:string, customer-city:string) LOAN(loan-number:int, branch-name:string, amount:real) BORROWER(customer-name:string, loan-number:int) (i) Create the above tables by properly specifying the primary keys and the for eign keys Branch create table branch ( bname varchar(10) primary key, city varchar(10), assets real ); Account create table account ( accno int primary key, bname varchar(10) references branch(bname), balance real, ); Cust create table cust ( cname varchar(10) primary key, cstreet varchar(10), city varchar(10) ); Depositor create table depositor ( cname varchar(10) references cust(cname), accno int references account(accno), ); Loan create table loan ( lno int primary key, bname varchar(10) references branch(bname), amt real, ); Borrower create table borrower ( cname varchar(10) references cust(cname), lno int references loan(lno), );
(ii) Enter at least five tuples for each relation
Branch insert into branch values('abc','bang',1200000); insert into branch values('def','che',2000000); insert into branch values('abn','mum',330000); insert into branch values('xyz','hyd',555555); insert into branch values('mno','bang',9999999); Account insert into account values(1,'abc',25000); insert into account values(2,'def',12000); insert into account values(3,'def',1000); insert into account values(4,'abn',10000); insert into account values(5,'mno',600000); insert into account values(6,'xyz',50000); Customer insert into cust values('mik','ab','bang'); insert into cust values('muj','cd','bang'); insert into cust values('maj','ef','che'); insert into cust values('waj','xy','del'); insert into cust values('prad','lm','mum'); insert into cust values('now','op','hyd'); Depositor insert into depositor values('mik',2); insert into depositor values('muj',1); insert into depositor values('muj',5); insert into depositor values('prad',4); insert into depositor values('maj',3); insert into depositor values('waj',6); insert into depositor values('mik',3); Loan insert into loan values(1,'abc',5000); insert into loan values(2,'def',1500); insert into loan values(3,'abn',10000); insert into loan values(4,'xyz',3500); insert into loan values(5,'mno',20000); Borrower insert into borrower values('mik',2); insert into borrower values('muj',1); insert into borrower values('prad',3); insert into borrower values('maj',4); insert into borrower values('waj',5); (iii) Find all the customers who have at least two accounts at the Main branch. select cname from account a,depositor d where a.accno=d.accno and bname='d ef' group by cname having count(*)>1; (iv) Find all the customers who have an account at all the branches located in a specific city. select cname from cust c where not exists (select bname from branch where city='bang' minus select bname from deposit or d,account a where d.accno=a.accno and d.cname=c.cname) and exists(select bname from branch where city='bang'); (v) Demonstrate how you delete tuples in ACCOUNT relation at every branch locate d in a specific city. delete from account where bname in (select bname from branch where city='che ');