GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL Plus
Go To First  |  Previous Question  |  
 SQL Plus  |  Question 132 of 132    Print  
Default Constraint
What is default constraint? How we you apply it?


  
Total Answers and Comments: 5 Last Update: June 15, 2009     Asked by: gagan87 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sreekanthjup
 
Default Contraint acts the same way as the other constraints like NOT NULL, UNIQUE, PRIMARY KEY............. do; they come into picture while data insertion is done into the table. It makes oracle insert a values automatically into table without being specified in the insert; for example:

CREATE TABLE TTEMP (NM VARCHAR2(10) DEFAULT 'Sreekanth', JOB VARCHAR2(10));

now we can skip from the NM column being filled:
INSERT INTO TTEMP VALUES (null,'sales'); or INSERT INTO TTEMP VALUES ('','sales');
in ordinary case without default constraint assigned.. NULL gets inserted but here 'Sreekanth' is inserted in each unspecified row.


Above answer was rated as good by the following members:
neelapu, himanshu_sapra, pakashraf
September 24, 2008 11:19:52   #1  
veerun14 Member Since: September 2008   Contribution: 4    

RE: Default Constraint
By default the columns hold NULL if nothing is specified.
You can specify NOT NULL if you dont want NULL to be an attribute

UNIQUE and CHECK are other constraints

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
September 26, 2008 15:01:34   #2  
hamsatharini Member Since: September 2008   Contribution: 2    

RE: Default Constraint
It specifies a default value for a new column or a new default for an existing column.
Oracle assigns this value to the column if a subsequent INSERT statement omits a value for the column.

A DEFAULT expression cannot contain references to other columns the pseudocolumns CURRVAL NEXTVAL LEVEL and ROWNUM or date constants that are not fully specified.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
January 19, 2009 10:20:38   #3  
sreekanthjup Member Since: January 2009   Contribution: 1    

RE: Default Constraint
Default Contraint acts the same way as the other constraints like NOT NULL UNIQUE PRIMARY KEY............. do; they come into picture while data insertion is done into the table. It makes oracle insert a values automatically into table without being specified in the insert; for example:

CREATE TABLE TTEMP (NM VARCHAR2(10) DEFAULT 'Sreekanth' JOB VARCHAR2(10));

now we can skip from the NM column being filled:
INSERT INTO TTEMP VALUES (null 'sales'); or INSERT INTO TTEMP VALUES ('' 'sales');
in ordinary case without default constraint assigned.. NULL gets inserted but here 'Sreekanth' is inserted in each unspecified row.

 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
April 19, 2009 07:27:35   #4  
rsmendu Member Since: April 2009   Contribution: 1    

RE: Default Constraint
When we create a constraint on a table and if that constraint is not named then Oracle gives a system default name to the constraint.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
June 15, 2009 08:17:46   #5  
gdurga Member Since: June 2009   Contribution: 5    

RE: Default Constraint

A coulumn can be given a default value by using DEFAULT option. This option prevents null values from entering the column if a row is inserted with out a value in to the table.
Ex:
.......
Hire_date DATE DEFAULT SYSDATE
.......


 
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