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

Dbms Lab 4

The document describes creating tables for bank branches and accounts in a database. It creates tables for the branch and account, inserts sample data, sets up a foreign key between them, then creates additional tables for loans with a foreign key to branches. It performs various queries and updates on the tables.

Uploaded by

Kakashi Hatake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Dbms Lab 4

The document describes creating tables for bank branches and accounts in a database. It creates tables for the branch and account, inserts sample data, sets up a foreign key between them, then creates additional tables for loans with a foreign key to branches. It performs various queries and updates on the tables.

Uploaded by

Kakashi Hatake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

create table Branch(Name char(20) primary key,City char(20),Assets number(20));

Table created.

SQL> desc branch;


Name Null? Type
----------------------------------------- -------- ----------------------------
NAME NOT NULL CHAR(20)
CITY CHAR(20)
ASSETS NUMBER(20)

SQL> insert into branch values('&name','&city',&assets);


Enter value for name: SBI Nerul
Enter value for city: Navi Mumbai
Enter value for assets: 5000000
old 1: insert into branch values('&name','&city',&assets)
new 1: insert into branch values('SBI Nerul','Navi Mumbai',5000000)

1 row created.

SQL> /
Enter value for name: B
Enter value for city: Thane
Enter value for assets: 6000000
old 1: insert into branch values('&name','&city',&assets)
new 1: insert into branch values('B ','Thane',6000000)

1 row created.

SQL> /
Enter value for name: C
Enter value for city: Mumbai
Enter value for assets: 7000000
old 1: insert into branch values('&name','&city',&assets)
new 1: insert into branch values('C','Mumbai',7000000)

1 row created.

SQL> /
Enter value for name: D
Enter value for city: Ghatkopar
Enter value for assets: 10000000r
old 1: insert into branch values('&name','&city',&assets)
new 1: insert into branch values('D','Ghatkopar',10000000r)
insert into branch values('D','Ghatkopar',10000000r)
*
ERROR at line 1:
ORA-00917: missing comma

SQL> /
Enter value for name: D
Enter value for city: Ghatkopar
Enter value for assets: 10000000
old 1: insert into branch values('&name','&city',&assets)
new 1: insert into branch values('D','Ghatkopar',10000000)

1 row created.
SQL> /
Enter value for name: E
Enter value for city: Dadar
Enter value for assets: 2000000000
old 1: insert into branch values('&name','&city',&assets)
new 1: insert into branch values('E','Dadar',2000000000)

1 row created.

SQL> select * from branch;

NAME CITY ASSETS


-------------------- -------------------- ----------
SBI Nerul Navi Mumbai 5000000
B Thane 6000000
C Mumbai 7000000
D Ghatkopar 10000000
E Dadar 2000000000

SQL> update branch set name='A' where name='SBI Nerul';

1 row updated.

SQL> select * from branch;

NAME CITY ASSETS


-------------------- -------------------- ----------
A Navi Mumbai 5000000
B Thane 6000000
C Mumbai 7000000
D Ghatkopar 10000000
E Dadar 2000000000

SQL> create table Account;


create table Account
*
ERROR at line 1:
ORA-00906: missing left parenthesis

SQL> create table Account(A-Number number(20) primary key,B-Name char(20), Balance


number(20));
create table Account(A-Number number(20) primary key,B-Name char(20), Balance
number(20))
*
ERROR at line 1:
ORA-00902: invalid datatype

SQL> create table Account(Number number(20) primary key,Name char(20), Balance


number(20));
create table Account(Number number(20) primary key,Name char(20), Balance
number(20))
*
ERROR at line 1:
ORA-00904: : invalid identifier

SQL> create table Account(ANumber number(20) primary key,Name char(20), Balance


number(20));

Table created.

SQL> desc account;


Name Null? Type
----------------------------------------- -------- ----------------------------
ANUMBER NOT NULL NUMBER(20)
NAME CHAR(20)
BALANCE NUMBER(20)

SQL> alter table account add foreign key(Name) refrences branch(name);


alter table account add foreign key(Name) refrences branch(name)
*
ERROR at line 1:
ORA-00905: missing keyword

SQL> alter table account add foreign key(Name) references branch(name);

Table altered.

SQL> desc account;


Name Null? Type
----------------------------------------- -------- ----------------------------
ANUMBER NOT NULL NUMBER(20)
NAME CHAR(20)
BALANCE NUMBER(20)

SQL> insert into account values(101,'F',2000);


insert into account values(101,'F',2000)
*
ERROR at line 1:
ORA-02291: integrity constraint (SYSTEM.SYS_C004062) violated - parent key not
found

SQL> insert into branch values('F','Dombivli',3000000);

1 row created.

SQL> insert into account values(101,'F',2000);

1 row created.

SQL> insert into account(&ANumber,'&name',&balance);


Enter value for anumber: 102
Enter value for name: A
Enter value for balance: 50000
old 1: insert into account(&ANumber,'&name',&balance)
new 1: insert into account(102,'A',50000)
insert into account(102,'A',50000)
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> insert into account values(101,'A',5000);


insert into account values(101,'A',5000)
*
ERROR at line 1:
ORA-00001: unique constraint (SYSTEM.SYS_C004061) violated

SQL> select * from account;

ANUMBER NAME BALANCE


---------- -------------------- ----------
101 F 2000

SQL> select * from branch;

NAME CITY ASSETS


-------------------- -------------------- ----------
A Navi Mumbai 5000000
B Thane 6000000
C Mumbai 7000000
D Ghatkopar 10000000
E Dadar 2000000000
F Dombivli 3000000

6 rows selected.

SQL> delete from branch where name='f';

0 rows deleted.

SQL> delete from branch where name='F';


delete from branch where name='F'
*
ERROR at line 1:
ORA-02292: integrity constraint (SYSTEM.SYS_C004062) violated - child record
found

SQL> delete from account where name='f';

0 rows deleted.

SQL> delete from account where name='F';

1 row deleted.

SQL> delete from branch where name='F';

1 row deleted.

SQL> update from branch set City='Pune' where name='A';


update from branch set City='Pune' where name='A'
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> update branch set City='Pune' where name='A';

1 row updated.
SQL> update branch set Assets=50000 where name='B';

1 row updated.

SQL> select count(name) where City='Mumbai';


select count(name) where City='Mumbai'
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> select count(name) from branch where City='Mumbai';

COUNT(NAME)
-----------
1

SQL> select count(name) from branch where Assets>=5000000 and Assets<=10000000;

COUNT(NAME)
-----------
3

SQL> select assets from branch order by assets desc;

ASSETS
----------
2000000000
10000000
7000000
5000000
50000

SQL> create table loan(Loannumber number(20),Bname char(20),Amount number(20));


create table loan(Loannumber number(20),Bname char(20),Amount number(20))
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> create table loan1(Loannumber number(20),Bname char(20),Amount number(20));


create table loan1(Loannumber number(20),Bname char(20),Amount number(20))
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

SQL> create table loan2(Loannumber number(20),Bname char(20),Amount number(20));

Table created.

SQL> alter table loan add primary key(Loannumber);


alter table loan add primary key(Loannumber)
*
ERROR at line 1:
ORA-00904: "LOANNUMBER": invalid identifier

SQL> create table loan5(Loannumber number(20) primary key,Bname char(20),Amount


number(20));

Table created.

SQL> alter table loan add foreign key(Bname) references branch(name);


alter table loan add foreign key(Bname) references branch(name)
*
ERROR at line 1:
ORA-00904: "BNAME": invalid identifier

SQL> alter table loan5 add foreign key(Bname) references branch(name);

Table altered.

SQL> insert into loan5 values(101,'B',500000);

1 row created.

SQL> select * from loan5;

LOANNUMBER BNAME AMOUNT


---------- -------------------- ----------
101 B 500000

SQL> select avg(Assets) from account group by name;


select avg(Assets) from account group by name
*
ERROR at line 1:
ORA-00904: "ASSETS": invalid identifier

SQL> select avg(Assets) from branch group by name;

AVG(ASSETS)
-----------
5000000
50000
10000000
7000000
2000000000

You might also like