
- •Objectivesj i
- •What Are Constraints?i
- •Constrainti Guidelinesi li
- •Definingi i Constraintsi
- •Definingi i Constraintsi
- •The NOT NULL Constrainti
- •The NOT NULL Constrainti
- •The UNIQUEI Key Constrainti
- •The UNIQUEI Key Constrainti
- •The PRIMARYI KEY Constrainti
- •The PRIMARYI KEY Constrainti
- •The FOREIGNI KEY Constrainti
- •The FOREIGNI KEY Constrainti
- •FOREIGNI KEY Constrainti Keywords
- •The CHECK Constrainti
- •Addingi a Constrainti
- •Addingi a Constrainti
- •Droppingi a Constrainti
- •Disablingi li Constraintsi
- •Enablingli Constraintsi
- •Viewingi i Constraintsi
- •Viewingi i the Columnsl Associatedi withi Constraintsi
- •Summary
- •Practicei Overviewi

Viewingi i Constraintsi
Query the USER_CONSTRAINTS table to view all constraint definitions and names.
SQL> |
SELECT |
constraint_name, constraint_type, |
2 |
|
search_condition |
3 |
FROM |
user_constraints |
4WHERE table_name = 'EMP';
|
|
|
|
|
CONSTRAINT_NAME |
C SEARCH_CONDITION |
|
|
------------------------ |
- ------------------------- |
|
|
SYS_C00674 |
C EMPNO IS NOT NULL |
|
|
SYS_C00675 |
C DEPTNO IS NOT NULL |
|
|
EMP_EMPNO_PK |
P |
|
|
... |
|
|
|
|
|
|
|
|
|
|
11-22

Viewingi i the Columnsl Associatedi withi Constraintsi
View the columns associated with the constraint names in the USER_CONS_COLUMNS view
|
|
|
|
|
|
|
SQL> |
SELECT |
constraint_name, column_name |
|
|
|
2 |
FROM |
user_cons_columns |
|
|
|
3 |
WHERE |
table_name = 'EMP'; |
|
|
|
|
|
|
||
|
|
|
|
|
|
|
|
|
|
||
|
CONSTRAINT_NAME |
COLUMN_NAME |
|
||
|
------------------------- |
---------------------- |
|
||
|
EMP_DEPTNO_FK |
|
DEPTNO |
|
|
|
EMP_EMPNO_PK |
|
EMPNO |
|
|
|
EMP_MGR_FK |
|
MGR |
|
|
|
SYS_C00674 |
|
EMPNO |
|
|
|
SYS_C00675 |
|
DEPTNO |
|
|
|
|
|
|
|
|
11-23

Summary
•• Creater te thet followingf ll i typest off constraints:tr i t :
–NOT NULL
–UNIQUEI key
–PRIMARYI KEY
–FOREIGNI KEY
–CHECK
•• Queryry thet USER_CONSTRAINTSI tablet le toto viewi allll constrainttr i t definitionsfi iti and names..
11-24

Practicei Overviewi
•Adding constraints to existing tables
•Adding constraints to existing tables
•Adding additional columns to a table
•Adding additional columns to a table
•Displaying information in data dictionary views
•Displaying information in data dictionary views
11-25