Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Constraints in SQL

Constraints in SQL

Ratings: (0)|Views: 19 |Likes:
Published by srvdhar

More info:

Published by: srvdhar on Mar 22, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

03/22/2011

pdf

text

original

 
Oracle "alter table" constraint
 
Syntax examples
 
Oracle Tips by Burleson Consulting 
 
W
e have "alter table" syntax from Oracle to add data constraints in-place in this form:
alter tabletable_nameadd constraintconstraint_name;
 
W
e can also use "alter table" syntax to enable or disable constraints:
alter tabletable_nameENABLE constraintconstraint_name;alter tabletable_nameDISABLE constraintconstraint_name;
 
Ch
eck 
Co
nstraint
 
W
e have details on the different types of constraints:
alter tabletable_nameadd constraintcheck_constraint_nameCHECK(check_column_name IN('check_constraint1_value','check_constraint2_value','check_constraint3_value','check_constraint4_value')) DISABLE|ENABLE;
 Here are some examples of Oracle "alter table" syntax to add foreign key constraints.
alter tablecust_tableadd constraintfk_cust_name FOREIGN KEY (person_name)references
 
person_table (person_name)initially deferred deferrable;
 Here is an example of a multiple column foreign key constraint:
alter tablecust_tableadd constraintfk_cust_name FOREIGN KEY (person_name, person_gender)referencesperson_table (person_name, person_gender)initially deferred deferrable;
 Here is another example of Oracle "alter table" syntax to drop constraints.
ALTER TABLEcust_tabledrop constraintfk_cust_table_ref;
 Here we use Oracle "alter table" syntax to add a check constraint.
alter tablecust_tableadd constraintcheck_cust_typesCHECK(cust_type IN('yuppie','dink','guppie'));
 
O
racle c
o
nstraint err
o
rs
 The following errors are associated with Oracle constraint alter commands:
y
 
ORA-02290: check constraint (owner.constraintname) violated
y
 
ORA-02291: integrity constraint (owner.constraintname) violated -parent key not found
y
 
ORA-02292:violated integrity constraint (owner.constraintname)- childrecord found
 
O
racle
Ch
eck 
Co
nstraint tips
 
Oracle Tips by Burleson Consulting 
 
O
racle
Ch
eck 
Co
nstraint
 Oracle check constraint insures that updated or inserted values meet a specific condition. TheOracle check constraint check condition must return a TRUE or FALSE, much Like the
W
HEREclause. If the Oracle check constraint condition returns as TRUE when you use Oracle check constraint, the value is accepted by the constraint. If Oracle check constraint returns thecondition as FALSE, the value is rejected. Below, we include an Oracle check constraint on the
editor_active
column of the EDITOR table that insures the value is either Y or N.To put it another way, Oracle check constraint validates incoming columns at row insert time.
W
ith Oracle check constraint, rather than having an application verify that all occurrences of REGION are North, South, East, or 
W
est, an Oracle CHECK constraint can be added to the tabledefinition to ensure the validity of the region column.Here is an example of Oracle check constraint:Oracle check constraint has some limitations. For one, subqueries cannot be used within your Oracle check constraints. Also, an Oracle check constraint is able to reference another column.Sysdate, currval, nextval, level, rowid, uid, user or userenv cannot be referenced with Oraclecheck constraint.Oracle check constraint cannot reference columns from other tables. There can be more than oneOracle check constraint per column, however the values being checked with Oracle check constraint must pass all Oracle check constraints on that column before being acceptable. Oraclecheck constraint can also be used to check multiple columns.

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->