Sei sulla pagina 1di 8

SQL> create table branch(branch_name varchar(10),branch_city varchar(10),assets

int,primary key(branch_name));

Table created.

SQL> create table account(accno int,branch_name varchar(10),balance int,primary


key(accno));

Table created.

SQL> create table customers(customer_name varchar(10),customer_street


varchar(10),customer_city varchar(10),primary key(customer_name));

Table created.

SQL> create table depositor(customer_name varchar(10),accno int,primary


key(customer_name,accno),foreign key(customer_name) references
customers(customer_name),foreign key(accno) references account(accno) on delete
cascade);

Table created.

SQL> create table loan(loan_number int,branch_name varchar(10),amount int,primary


key(loan_number),foreign key(branch_name) references branch(branch_name));

Table created.

SQL> create table borrower(customer_name varchar(10),loan_number int,primary


key(customer_name,loan_number),foreign key(customer_name) references
customers(customer_name),foreign key(loan_number) references loan(loan_number));

Table created.

SQL> desc branch;


Name Null? Type
----------------------------------------- -------- ----------------------------
BRANCH_NAME NOT NULL VARCHAR2(10)
BRANCH_CITY VARCHAR2(10)
ASSETS NUMBER(38)

SQL> desc account;


Name Null? Type
----------------------------------------- -------- ----------------------------
ACCNO NOT NULL NUMBER(38)
BRANCH_NAME VARCHAR2(10)
BALANCE NUMBER(38)

SQL> desc customers;


Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMER_NAME NOT NULL VARCHAR2(10)
CUSTOMER_STREET VARCHAR2(10)
CUSTOMER_CITY VARCHAR2(10)

SQL> desc depositor;


Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMER_NAME NOT NULL VARCHAR2(10)
ACCNO NOT NULL NUMBER(38)

SQL> desc loan;


Name Null? Type
----------------------------------------- -------- ----------------------------
LOAN_NUMBER NOT NULL NUMBER(38)
BRANCH_NAME VARCHAR2(10)
AMOUNT NUMBER(38)

SQL> desc borrower;


Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMER_NAME NOT NULL VARCHAR2(10)
LOAN_NUMBER NOT NULL NUMBER(38)

SQL> insert into branch values('&branch_name','&branch_city',&assets);


Enter value for branch_name: sbi
Enter value for branch_city: kollam
Enter value for assets: 5
old 1: insert into branch values('&branch_name','&branch_city',&assets)
new 1: insert into branch values('sbi','kollam',5)

1 row created.

SQL> insert into branch values('&branch_name','&branch_city',&assets);


Enter value for branch_name: canara
Enter value for branch_city: kundara
Enter value for assets: 7
old 1: insert into branch values('&branch_name','&branch_city',&assets)
new 1: insert into branch values('canara','kundara',7)

1 row created.

SQL> insert into branch values('&branch_name','&branch_city',&assets);


Enter value for branch_name: southindia
Enter value for branch_city: tvm
Enter value for assets: 8
old 1: insert into branch values('&branch_name','&branch_city',&assets)
new 1: insert into branch values('southindia','tvm',8)

1 row created.

SQL> insert into branch values('&branch_name','&branch_city',&assets);


Enter value for branch_name: federal
Enter value for branch_city: erklm
Enter value for assets: 3
old 1: insert into branch values('&branch_name','&branch_city',&assets)
new 1: insert into branch values('federal','erklm',3)
1 row created.

SQL> insert into branch values('&branch_name','&branch_city',&assets);


Enter value for branch_name: boi
Enter value for branch_city: ktym
Enter value for assets: 4
old 1: insert into branch values('&branch_name','&branch_city',&assets)
new 1: insert into branch values('boi','ktym',4)

1 row created.

SQL> select * from branch;

BRANCH_NAM BRANCH_CIT ASSETS


---------- ---------- ----------
sbi kollam 5
canara kundara 7
southindia tvm 8
federal erklm 3
boi ktym 4

SQL> insert into account values(&accno,'&branch_name',&balance);


Enter value for accno: 65789
Enter value for branch_name: sbi
Enter value for balance: 5000
old 1: insert into account values(&accno,'&branch_name',&balance)
new 1: insert into account values(65789,'sbi',5000)

1 row created.

SQL> insert into account values(&accno,'&branch_name',&balance);


Enter value for accno: 93267
Enter value for branch_name: boi
Enter value for balance: 20000
old 1: insert into account values(&accno,'&branch_name',&balance)
new 1: insert into account values(93267,'boi',20000)

1 row created.

SQL> insert into account values(&accno,'&branch_name',&balance);


Enter value for accno: 59201
Enter value for branch_name: sbi
Enter value for balance: 10000
old 1: insert into account values(&accno,'&branch_name',&balance)
new 1: insert into account values(59201,'sbi',10000)

1 row created.

SQL> insert into account values(&accno,'&branch_name',&balance);


Enter value for accno: 78391
Enter value for branch_name: federal
Enter value for balance: 7000
old 1: insert into account values(&accno,'&branch_name',&balance)
new 1: insert into account values(78391,'federal',7000)

1 row created.
SQL> insert into account values(&accno,'&branch_name',&balance);
Enter value for accno: 89402
Enter value for branch_name: southindia
Enter value for balance: 100000
old 1: insert into account values(&accno,'&branch_name',&balance)
new 1: insert into account values(89402,'southindia',100000)

1 row created.

SQL> select * from account;

ACCNO BRANCH_NAM BALANCE


---------- ---------- ----------
65789 sbi 5000
93267 boi 20000
59201 sbi 10000
78391 federal 7000
89402 southindia 100000

SQL> insert into customers


values('&customer_name','&customer_street','&customer_city');
Enter value for customer_name: vijay
Enter value for customer_street: green
Enter value for customer_city: kilm
old 1: insert into customers
values('&customer_name','&customer_street','&customer_city')
new 1: insert into customers values('vijay','green','kilm')

1 row created.

SQL> insert into customers


values('&customer_name','&customer_street','&customer_city');
Enter value for customer_name: surya
Enter value for customer_street: tagore
Enter value for customer_city: ktym
old 1: insert into customers
values('&customer_name','&customer_street','&customer_city')
new 1: insert into customers values('surya','tagore','ktym')

1 row created.

SQL> insert into customers


values('&customer_name','&customer_street','&customer_city');
Enter value for customer_name: varun
Enter value for customer_street: vrindhavan
Enter value for customer_city: erklm
old 1: insert into customers
values('&customer_name','&customer_street','&customer_city')
new 1: insert into customers values('varun','vrindhavan','erklm')

1 row created.

SQL> insert into customers


values('&customer_name','&customer_street','&customer_city');
Enter value for customer_name: siddharth
Enter value for customer_street: sm strt
Enter value for customer_city: tvm
old 1: insert into customers
values('&customer_name','&customer_street','&customer_city')
new 1: insert into customers values('siddharth','sm strt','tvm')

1 row created.

SQL> insert into customers


values('&customer_name','&customer_street','&customer_city');
Enter value for customer_name: akshay
Enter value for customer_street: tsstrt
Enter value for customer_city: erklm
old 1: insert into customers
values('&customer_name','&customer_street','&customer_city')
new 1: insert into customers values('akshay','tsstrt','erklm')

1 row created.

SQL> select * from customers;

CUSTOMER_N CUSTOMER_S CUSTOMER_C


---------- ---------- ----------
vijay green kilm
surya tagore ktym
varun vrindhavan erklm
siddharth sm strt tvm
akshay tsstrt erklm

insert into depositor values('&customer_name',&accno);


Enter value for customer_name: vijay
Enter value for accno: 65789
old 1: insert into depositor values('&customer_name',&accno)
new 1: insert into depositor values('vijay',65789)

1 row created.

SQL> insert into depositor values('&customer_name',&accno);


Enter value for customer_name: surya
Enter value for accno: 93267
old 1: insert into depositor values('&customer_name',&accno)
new 1: insert into depositor values('surya',93267)

1 row created.

SQL> insert into depositor values('&customer_name',&accno);


Enter value for customer_name: varun
Enter value for accno: 59201
old 1: insert into depositor values('&customer_name',&accno)
new 1: insert into depositor values('varun',59201)

1 row created.

SQL> insert into depositor values('&customer_name',&accno);


Enter value for customer_name: siddharth
Enter value for accno: 78391
old 1: insert into depositor values('&customer_name',&accno)
new 1: insert into depositor values('siddharth',78391)

1 row created.

SQL> insert into depositor values('&customer_name',&accno);


Enter value for customer_name: akshay
Enter value for accno: 89402
old 1: insert into depositor values('&customer_name',&accno)
new 1: insert into depositor values('akshay',89402)

1 row created.

SQL> select * from depositor;

CUSTOMER_N ACCNO
---------- ----------
vijay 65789
surya 93267
varun 59201
siddharth 78391
akshay 89402

SQL>
SQL> insert into loan values(&loan_number,'&branch_name',&amount);
Enter value for loan_number: 10
Enter value for branch_name: sbi
Enter value for amount: 500000
old 1: insert into loan values(&loan_number,'&branch_name',&amount)
new 1: insert into loan values(10,'sbi',500000)

1 row created.

SQL> insert into loan values(&loan_number,'&branch_name',&amount);


Enter value for loan_number: 43
Enter value for branch_name: boi
Enter value for amount: 1000000
old 1: insert into loan values(&loan_number,'&branch_name',&amount)
new 1: insert into loan values(43,'boi',1000000)

1 row created.

SQL> insert into loan values(&loan_number,'&branch_name',&amount);


Enter value for loan_number: 12
Enter value for branch_name: sbi
Enter value for amount: 300000
old 1: insert into loan values(&loan_number,'&branch_name',&amount)
new 1: insert into loan values(12,'sbi',300000)

1 row created.

SQL> insert into loan values(&loan_number,'&branch_name',&amount);


Enter value for loan_number: 89
Enter value for branch_name: federal
Enter value for amount: 700000
old 1: insert into loan values(&loan_number,'&branch_name',&amount)
new 1: insert into loan values(89,'federal',700000)

1 row created.
SQL> insert into loan values(&loan_number,'&branch_name',&amount);
Enter value for loan_number: 37
Enter value for branch_name: southindia
Enter value for amount: 200000
old 1: insert into loan values(&loan_number,'&branch_name',&amount)
new 1: insert into loan values(37,'southindia',200000)

1 row created.

SQL> select * from loan;

LOAN_NUMBER BRANCH_NAM AMOUNT


----------- ---------- ----------
10 sbi 500000
43 boi 1000000
12 sbi 300000
89 federal 700000
37 southindia 200000

SQL> insert into borrower values('&customer_name',&loan_number);


Enter value for customer_name: vijay
Enter value for loan_number: 10
old 1: insert into borrower values('&customer_name',&loan_number)
new 1: insert into borrower values('vijay',10)

1 row created.

SQL> insert into borrower values('&customer_name',&loan_number);


Enter value for customer_name: surya
Enter value for loan_number: 43
old 1: insert into borrower values('&customer_name',&loan_number)
new 1: insert into borrower values('surya',43)

1 row created.

SQL> insert into borrower values('&customer_name',&loan_number);


Enter value for customer_name: varun
Enter value for loan_number: 12
old 1: insert into borrower values('&customer_name',&loan_number)
new 1: insert into borrower values('varun',12)

1 row created.

SQL> insert into borrower values('&customer_name',&loan_number);


Enter value for customer_name: siddharth
Enter value for loan_number: 89
old 1: insert into borrower values('&customer_name',&loan_number)
new 1: insert into borrower values('siddharth',89)

1 row created.

SQL> insert into borrower values('&customer_name',&loan_number);


Enter value for customer_name: akshay
Enter value for loan_number: 37
old 1: insert into borrower values('&customer_name',&loan_number)
new 1: insert into borrower values('akshay',37)
1 row created.

SQL> select * from borrower;

CUSTOMER_N LOAN_NUMBER
---------- -----------
vijay 10
surya 43
varun 12
siddharth 89
akshay 37

SQL> select d.customer_name from depositor d,account a where a.accno=d.accno and


a.branch_name='sbi' group by d.customer_name having count(*)=1;

CUSTOMER_N
----------
varun
vijay

SQL> select c.customer_name from customers c where exists(select branch_name from


branch where branch_city='tvm') and not exists ((select branch_name from branch
where branch_city='tvm') minus (select b.branch_name from branch b,account
a,depositor d where d.customer_name=c.customer_name and d.accno=a.accno and
a.branch_name=b.branch_name));

CUSTOMER_N
----------
akshay

SQL> delete from account where accno in (select a.accno from account a,branch b
where a.branch_name=b.branch_name and b.branch_city='erklm');

1 row deleted.

Potrebbero piacerti anche