Aspirant
Aspirant

Reputation: 2278

how to modify a constraint in sql plus?

I have created a table as follows:

create table emp( emp_id number(5) primary key
                , emp_name varchar(20) not null
                , dob date );

After the table has been created how would I change the constraint not null to unique or any other constraint in SQL*Plus?

Upvotes: 1

Views: 3788

Answers (3)

peridin
peridin

Reputation: 28

We cant be able to modify the already added constraint. Just we have to drop the constraint and add the new one with the same name, but add it with the necessary changes.

ALTER TABLE  table_name drop constraint contraint_name;

alter table tablename add constraint containt_name CHECK (column_name IN (changes in the contraint)) ENABLE;

Upvotes: 0

Justin Cave
Justin Cave

Reputation: 231821

You don't change a constraint from one type to another. You can add a unique constraint to the table

ALTER TABLE emp 
  ADD ( COSTRAINT uk_emp_name UNIQUE( emp_name ) );

That is independent of whether emp_name is allowed to have NULL values.

Upvotes: 3

psur
psur

Reputation: 4519

Just use ALTER TABLE command. For details look here: http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_3001.htm#i2103817

Upvotes: 0

Related Questions