Professional Documents
Culture Documents
Columns.
manipulated by other users
columns.
Table columns.
on table columns.
Index :
It is a pointer locates the physical address of data.
It will improve performance of oracle while
Retrieving or Manipul
ating data using Key column.
It is automatically activated whenever key column
is used in "Where" clause
.
* References ( Foreign Key ) :
Used to define relationship between 2 Tables.
It allows Null and duplicate values .
constraint column of o
T1
T2
----c1 (pk/unq)
c1 (fk)
T1.c1 = T2.c1
--------------------------------------------------------------dept
emp
----------deptno (pk)
deptno (fk)
dept.deptno = emp.deptno
* one - many or many - one Relation established
between PK and FK.
-------------------------------------------------------------Note:
Constraints are defined in 2 Methods:
1. Column Constraint Syntax
2. Table Constraint Syntax
1. Column Constraint Syntax
constraints are defined at the end of column
definition.
All constraints are supported.
Used to define constraints only while creating Tables
Using Column constraint Syntax:
create table dept
(deptno number(2) primary key,
dname varchar2(20) not null unique,
loc varchar2(20) default 'Hyderabad');
insert into dept values (10,'SALES','MUMBAI');
insert into dept values (null,'HR','PUNE');
insert into dept values (10,'ADMIN','NOIDA');
insert into dept values (20, null ,'Secbad');
insert into dept values (30,'Sales','GOA');
--------------------------------------------------------------Activating default :
insert into dept values(40,'TRAINING',default);
* Default : keyword (8.0)
used to replace with default value defined
insert into dept(deptno,dname)
values(50,'TESTING');
insert into dept values(60,'RESEARCH',null);
insert into dept values(70,'HR'); -- error
select * from dept;
40 TRAINING Hyderabad
50 TESTING
Hyderabad
60 RESEARCH
--------------------------------------------------------------select * from dept where deptno = 10;
update dept set loc = 'VIZAG' where deptno = 30;
-- Index is activated automatically while Retrieving
or Manipulating data th
ru key column in WHERE
clause.
--------------------------------------------------------------Create table emp
(empno number(4) primary key,
ename varchar2(20) not null,
sex char(1) check (sex in ('M','F')),
(10,20,30,40)
values(101,...........,10);
values(102,...........,20);
values(103,...........,30);
values(104,...........,10);
values(105,...........,10);
values(108,...........,null);
values(110,...........,90); -- error
not found (2291)
parent ( 2292 )
into
into
into
into
into
incr
incr
incr
incr
incr
values(101,10000);
values(105,10000);
values(103,5000);
values(105,5000);
values(null,10000); -- error
(null value)
delete
3
2
1
exists.
dropped.
101 500
101 600
15-mar-11
30-mar-11
unique(dname);
information existing da
sysdate;
P
C
U
R
of constraints defined
information about the co
user_constraints where
(PK)
(Chk / NN )
(Unq)
(Ref)