Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

SQL> create table fviews(name varchar2(20),no number(5),sal number(5),dno number(5));

Table created.

SQL> insert into fviews values('xxx',1,19000,11);

1 row created.

SQL> insert into fviews values('aaa',2,19000,12);

1 row created.

SQL> insert into fviews values('yyy',3,40000,13);

1 row created.

SQL> select*from fviews;

NAME NO SAL DNO

-------------------- ---------- ---------- ----------

xxx 1 19000 11

aaa 2 19000 12

yyy 3 40000 13

SQL> create table dviews(dno number(5),dname varchar2(20));

Table created.

SQL> insert into dviews values(11,'x');

1 row created.

SQL> insert into dviews values(12,'y');

1 row created.

SQL> select*from dviews;

DNO DNAME

---------- --------------------

11 x

12 y

8208E21CSR020
SQL> create view sview as select name,no,sal,dno from fviews where dno=11;

View created.

SQL> select*from sview;

NAME NO SAL DNO

-------------------- ---------- ---------- ----------

xxx 1 19000 11

SQL> insert into sview values('zzz',4,20000,14);

1 row created.

SQL> select*from sview;

NAME NO SAL DNO

-------------------- ---------- ---------- ----------

xxx 1 19000 11

SQL> select*from fviews;

NAME NO SAL DNO

-------------------- ---------- ---------- ----------

xxx 1 19000 11

aaa 2 19000 12

yyy 3 40000 13

zzz 4 20000 14

SQL> create view iview as select*from fviews;

View created.

SQL> select*from iview;

NAME NO SAL DNO

-------------------- ---------- ---------- ----------

xxx 1 19000 11

8208E21CSR020
aaa 2 19000 12

yyy 3 40000 13

zzz 4 20000 14

SQL> insert into iview values('bbb',5,30000,15);

1 row created.

SQL> select*from fviews;

NAME NO SAL DNO

-------------------- ---------- ---------- ----------

xxx 1 19000 11

aaa 2 19000 12

yyy 3 40000 13

zzz 4 20000 14

bbb 5 30000 15

SQL> create view ssview(cusname,id)as select name,no from fviews where dno=12;

View created.

SQL> select*from ssview;

CUSNAME ID

-------------------- ----------

aaa 2

SQL> drop view ssview;

View dropped.

SQL> create view combo as select name,no,sal,dviews.dno,dname from fviews,dviews where


fviews.dno=dviews.dno;

View created.

SQL> select*from combo;

NAME NO SAL DNO DNAME

8208E21CSR020
-------------------- ---------- ---------- ---------- --------------------

xxx 1 19000 11 x

aaa 2 19000 12 y

SQL> insert into combo values('ccc',12000,13,'x');

insert into combo values('ccc',12000,13,'x')

ERROR at line 1:

ORA-00947: not enough values

SQL> create table customer(cname varchar2(20),accno number constraint consn null);

Table created.

SQL> desc customer;

Name Null? Type

----------------------------------------- -------- ----------------------------

CNAME VARCHAR2(20)

ACCNO NUMBER

SQL> insert into customer values('&cname',&accno);

Enter value for cname: x

Enter value for accno: 1

old 1: insert into customer values('&cname',&accno)

new 1: insert into customer values('x',1)

1 row created.

SQL> /

Enter value for cname: y

Enter value for accno: 2

8208E21CSR020
old 1: insert into customer values('&cname',&accno)

new 1: insert into customer values('y',2)

1 row created.

SQL> /

Enter value for cname: z

Enter value for accno: null

old 1: insert into customer values('&cname',&accno)

new 1: insert into customer values('z',null)

1 row created.

SQL> select*from customer;

CNAME ACCNO

-------------------- ----------

x 1

y 2

SQL> update customer set accno=3 where cname='z';

1 row updated.

SQL> select*from customer;

CNAME ACCNO

-------------------- ----------

x 1

y 2

z 3

SQL> create table borrower(cname varchar2(20),loan_no number constraint consl not null);

8208E21CSR020
Table created.

SQL> insert into borrower values('&cname',&loan_no);

Enter value for cname: x

Enter value for loan_no: 1

old 1: insert into borrower values('&cname',&loan_no)

new 1: insert into borrower values('x',1)

1 row created.

SQL> /

Enter value for cname: y

Enter value for loan_no: 2

old 1: insert into borrower values('&cname',&loan_no)

new 1: insert into borrower values('y',2)

1 row created.

SQL> /

Enter value for cname: z

Enter value for loan_no: null

old 1: insert into borrower values('&cname',&loan_no)

new 1: insert into borrower values('z',null)

insert into borrower values('z',null)

ERROR at line 1:

ORA-01400: cannot insert NULL into ("SYSTEM"."BORROWER"."LOAN_NO")

SQL> /

Enter value for cname: a

Enter value for loan_no:

8208E21CSR020
old 1: insert into borrower values('&cname',&loan_no)

new 1: insert into borrower values('a',)

insert into borrower values('a',)

ERROR at line 1:

ORA-00936: missing expression

SQL> select*from borrower;

CNAME LOAN_NO

-------------------- ---------------

x 1

y 2

SQL> create table withdraw(cname varchar2(20),balance number constraint consc check(balance>500));

Table created.

SQL> insert into withdraw values('&cname',&balance);

Enter value for cname: x

Enter value for balance: 10000

old 1: insert into withdraw values('&cname',&balance)

new 1: insert into withdraw values('x',10000)

1 row created.

SQL> /

Enter value for cname: y

Enter value for balance: 200

old 1: insert into withdraw values('&cname',&balance)

new 1: insert into withdraw values('y',200)

insert into withdraw values('y',200)

8208E21CSR020
*

ERROR at line 1:

ORA-02290: check constraint (SYSTEM.CONSC) violated

SQL> /

Enter value for cname: y

Enter value for balance: 20000

old 1: insert into withdraw values('&cname',&balance)

new 1: insert into withdraw values('y',20000)

1 row created.

SQL> select*from withdraw;

CNAME BALANCE

-------------------- --------------

x 10000

y 20000

SQL> update withdraw set balance=balance-9700 where cname='x';

update withdraw set balance=balance-9700 where cname='x'

ERROR at line 1:

ORA-02290: check constraint (SYSTEM.CONSC) violated

SQL> create table company(comp_name varchar2(20) not null unique,location varchar2(20) not null
unique);

Table created.

SQL> desc company;

Name Null? Type

----------------------------------------- -------- ----------------------------

COMP_NAME NOT NULL VARCHAR2(20)

8208E21CSR020
LOCATION NOT NULL VARCHAR2(20)

SQL> insert into company values('&comp_name','&location');

Enter value for comp_name: tcs

Enter value for location: kochi

old 1: insert into company values('&comp_name','&location')

new 1: insert into company values('tcs','kochi')

1 row created.

SQL> /

Enter value for comp_name: wipro

Enter value for location: bangalore

old 1: insert into company values('&comp_name','&location')

new 1: insert into company values('wipro','bangalore')

1 row created.

SQL> /

Enter value for comp_name: tcs

Enter value for location: chennai

old 1: insert into company values('&comp_name','&location')

new 1: insert into company values('tcs','chennai')

insert into company values('tcs','chennai')

ERROR at line 1:

ORA-00001: unique constraint (SYSTEM.SYS_C003998) violated

SQL> /

Enter value for comp_name: cts

Enter value for location: kochi

8208E21CSR020
old 1: insert into company values('&comp_name','&location')

new 1: insert into company values('cts','kochi')

insert into company values('cts','kochi')

ERROR at line 1:

ORA-00001: unique constraint (SYSTEM.SYS_C003999) violated

SQL> /

Enter value for comp_name: null

Enter value for location: mumbai

old 1: insert into company values('&comp_name','&location')

new 1: insert into company values('null','mumbai')

1 row created.

SQL> /

Enter value for comp_name:

Enter value for location: trichy

old 1: insert into company values('&comp_name','&location')

new 1: insert into company values('','trichy')

insert into company values('','trichy')

ERROR at line 1:

ORA-01400: cannot insert NULL into ("SYSTEM"."COMPANY"."COMP_NAME")

SQL> /

Enter value for comp_name: infosys

Enter value for location:

old 1: insert into company values('&comp_name','&location')

8208E21CSR020
new 1: insert into company values('infosys','')

insert into company values('infosys','')

ERROR at line 1:

ORA-01400: cannot insert NULL into ("SYSTEM"."COMPANY"."LOCATION")

SQL> select*from company;

COMP_NAME LOCATION

-------------------- --------------------

tcs kochi

wipro bangalore

null mumbai

SQL> create table account(accno number constraint consu unique);

Table created.

SQL> insert into account values(&accno);

Enter value for accno: 1

old 1: insert into account values(&accno)

new 1: insert into account values(1)

1 row created.

SQL> /

Enter value for accno: 2

old 1: insert into account values(&accno)

new 1: insert into account values(2)

1 row created.

SQL> /

Enter value for accno: 3

8208E21CSR020
old 1: insert into account values(&accno)

new 1: insert into account values(3)

1 row created.

SQL> /

Enter value for accno: 2

old 1: insert into account values(&accno)

new 1: insert into account values(2)

insert into account values(2)

ERROR at line 1:

ORA-00001: unique constraint (SYSTEM.CONSU) violated

SQL> alter table account add(cname varchar2(20));

Table altered.

SQL> desc account;

Name Null? Type

----------------------------------------- -------- ----------------------------

ACCNO NUMBER

CNAME VARCHAR2(20)

SQL> alter table account add constraint consu unique(cname);

alter table account add constraint consu unique(cname)

ERROR at line 1:

ORA-02264: name already used by an existing constraint

SQL> alter table account add constraint consu unique(cname);

alter table account add constraint consu unique(cname)

8208E21CSR020
*

ERROR at line 1:

ORA-02264: name already used by an existing constraint

SQL> desc account;

Name Null? Type

----------------------------------------- -------- ----------------------------

ACCNO NUMBER

CNAME VARCHAR2(20)

SQL> select*from account;

ACCNO CNAME

---------- --------------------

SQL> update account set cname='y' where accno=1;

1 row updated.

SQL> update account set cname='z' where accno=2;

1 row updated.

SQL> update account set cname='a' where accno=3;

1 row updated.

SQL> select*from account;

ACCNO CNAME

---------- --------------------

1 y

2 z

8208E21CSR020
3 a

SQL> create table empv(name varchar2(20),id number primary key);

Table created.

SQL> desc empv;

Name Null? Type

----------------------------------------- -------- ----------------------------

NAME VARCHAR2(20)

ID NOT NULL NUMBER

SQL> insert into empv values('&name',&id);

Enter value for name: abishek

Enter value for id: 1

old 1: insert into empv values('&name',&id)

new 1: insert into empv values('abishek',1)

1 row created.

SQL> /

Enter value for name: krishna

Enter value for id: 11

old 1: insert into empv values('&name',&id)

new 1: insert into empv values('krishna',11)

1 row created.

SQL> /

Enter value for name: krishna

Enter value for id: 12

old 1: insert into empv values('&name',&id)

new 1: insert into empv values('krishna',12)

8208E21CSR020
1 row created.

SQL> select*from empv;

NAME ID

-------------------- ----------

abishek 1

krishna 11

krishna 12

SQL> create table project(pname varchar2(20),id number not null,constraint.cons_for foreign key(id)
references empv(id));

create table project(pname varchar2(20),id number not null,constraint.cons_for foreign key(id)


references empv(id))

ERROR at line 1:

ORA-01748: only simple column names allowed here

SQL> create table project(pname varchar2(20),id number not null,constraint cons_for foreign key(id)
references empv(id));

Table created.

SQL> desc project;

Name Null? Type

----------------------------------------- -------- ----------------------------

PNAME VARCHAR2(20)

ID NOT NULL NUMBER

SQL> insert into project values('&pname',&id);

Enter value for pname: banking_system

Enter value for id: 11

old 1: insert into project values('&pname',&id)

8208E21CSR020
new 1: insert into project values('banking_system',11)

1 row created.

SQL> /

Enter value for pname: banking_system

Enter value for id: 12

old 1: insert into project values('&pname',&id)

new 1: insert into project values('banking_system',12)

1 row created.

SQL> /

Enter value for pname: airline

Enter value for id: 11

old 1: insert into project values('&pname',&id)

new 1: insert into project values('airline',11)

1 row created.

SQL> /

Enter value for pname: payroll

Enter value for id: 12

old 1: insert into project values('&pname',&id)

new 1: insert into project values('payroll',12)

1 row created.

SQL> select*project;

select*project

ERROR at line 1:

ORA-00923: FROM keyword not found where expected

8208E21CSR020
SQL> select*from project;

PNAME ID

------------------------ ----------

banking_system 11

banking_system 12

airline 11

payroll 12

SQL> select name,empv.id,pname from empv,project where empv.id=project.id;

NAME ID PNAME

-------------------- ---------- --------------------

abishek 11 banking_system

krishna 12 banking_system

abishek 11 airline

krishna 12 payroll

8208E21CSR020

You might also like