Apr 6, 2013

How to Create Table in Oracle...


-- creating table with constraints but without names to the constraint
create table t1
(empno number primary key,
ename varchar2(10) not null,
invno char(5) unique,
sal number check (sal >= 5000))

-- Displaying the inbuilt names of constraints
desc user_constraints
select constraint_name,constraint_type,table_name from user_constraints
where table_name='T1';

-- creating table with names to constraint
create table t2
(empno number constraint pk primary key,
 ename varchar2(10) not null,
 invno number constraint uinvno unique,
 sal number constraint chsal check(sal >= 5000));

-- Displaying the user defined names of constraints
select constraint_name,constraint_type,table_name from user_constraints
where table_name='T2';

--Table level constraints
create table t3
(empno number,
 invno varchar2(10),
 ename varchar2(10) not null,
 issuedate date,
 returndate date,
 constraint compk primary key (empno,invno),
 constraint un unique (ename),
 constraint chdate check (returndate >= issuedate));
 
-- Foreign key
create table X
(empno number constraint fk references t1(empno) on delete cascade,
 marks number);

No comments:

OraApps Search

Custom Search

Search This Blog