0% found this document useful (0 votes)
121 views

Database Lab Program

1. Six database tables are created - BRANCH, ACCOUNT, CUSTOMER, DEPOSITOR, LOAN, BORROWER - with primary keys and foreign keys defined 2. At least five tuples are inserted into each table 3. A query finds customers with at least two accounts at the main branch 4. A query finds customers with an account at all branches in a specific city 5. A query demonstrates deleting tuples from the ACCOUNT table for branches in a specific city
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Database Lab Program

1. Six database tables are created - BRANCH, ACCOUNT, CUSTOMER, DEPOSITOR, LOAN, BORROWER - with primary keys and foreign keys defined 2. At least five tuples are inserted into each table 3. A query finds customers with at least two accounts at the main branch 4. A query finds customers with an account at all branches in a specific city 5. A query demonstrates deleting tuples from the ACCOUNT table for branches in a specific city
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Create a table and perform the following basic mysql operations


a) Set the primary key
b) Alter the structure of the table
c) Insert values
d) Delete values based on constraints
e) Display values using various forms of select clause
f) Drop the table
8. 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 foreign 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='def' 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');

You might also like