GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 175 of 241    Print  
how to create a constraint for a tablecolumn which is already created

  
Total Answers and Comments: 3 Last Update: May 03, 2008     Asked by: subbaraovangalli 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: krishnaindia2007
 
To add  primary key or unique key constraint

Alter table tablename add constraint constraintname  primary key / unique (column name)

To add check constraint
Alter table tablename add constraint constraintname  check (codition)


To add not null constraint
Alter table tablename modify (columnname not null)

To add  foreign key constraint
Alter table tablename add constraint constraintname foreign key(columnname) references referencedtablename(referenced columnname)

Note- We can not add primary key or not null constraint on  a column that contains null values.
We can not add unique key or primary key constraint on a column that constains duplicate vlaues



Above answer was rated as good by the following members:
vanishavadlya
April 06, 2007 08:24:33   #1  
priya_sri        

RE: how to create a constraint for a tablecolumn which...
Hi You can create constraints using Alter commandAlter table add constraint column
 
Is this answer useful? Yes | No
April 09, 2007 04:35:29   #2  
hindol_saha Member Since: March 2007   Contribution: 15    

RE: how to create a constraint for a tablecolumn which...

ALTER TABLE STUDENT ADD CONSTRAINT PK_STD_ID PRIMARY KEY (STUDENT_ID);


 
Is this answer useful? Yes | No
May 03, 2008 05:00:06   #3  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

RE: how to create a constraint for a tablecolumn which is already created
To add primary key or unique key constraint

Alter table tablename add constraint constraintname primary key / unique (column name)

To add check constraint
Alter table tablename add constraint constraintname check (codition)


To add not null constraint
Alter table tablename modify (columnname not null)

To add foreign key constraint
Alter table tablename add constraint constraintname foreign key(columnname) references referencedtablename(referenced columnname)

Note- We can not add primary key or not null constraint on a column that contains null values.
We can not add unique key or primary key constraint on a column that constains duplicate vlaues


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape