| Constraint type | Abbreviation |
|---|---|
| references (foreign key) | fk |
| unique | un |
| primary key | pk |
| check | ck |
| not null | nn |
In reality, this won't be possible because of the character limitation on names inside oracle. When the name is too long, we will follow these two steps in order:
Notes:
create table example_topics (
topic_id integer
constraint example_topics_topic_id_pk
primary key
);
create table constraint_naming_example (
example_id integer
constraint cne_example_id_pk
primary key,
one_line_description varchar(100)
constraint cne_one_line_desc_nn
not null,
body clob,
up_to_date_p char(1) default('t')
constraint cne_up_to_date_p_check
check(up_to_date_p in ('t','f')),
topic_id constraint cne_topic_id_nn not null
constraint cne_topic_id_fk references example_topics,
-- Define table level constraint
constraint cne_example_id_one_line_unq unique(example_id, one_line_description)
);
SQL> set autotrace traceonly explain; SQL> select * from constraint_naming_example, example_topics where constraint_naming_example.topic_id = example_topics.topic_id; Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=CHOOSE 1 0 NESTED LOOPS 2 1 TABLE ACCESS (FULL) OF 'CONSTRAINT_NAMING_EXAMPLE' 3 1 INDEX (UNIQUE SCAN) OF 'EXAMPLE_TOPICS_TOPIC_ID_PK' (UNI QUE)Isn't it nice to see "EXAMPLE_TOPICS_TOPIC_ID_PK" in the trace and know exactly which table oracle is using at each step?
About Naming the not null constraints
Though naming "not null" constraints doesn't help immeditately in error
debugging (e.g. the error will say something like
"Cannot insert null value into column"), we recommend naming not null
constraints to be consistent in our naming of all constraints.
| mbryzek@arsdigita.com | Last modified: 2001/01/21 01:49:07 |