Index: openacs-4/packages/acs-core-docs/www/eng-standards-constraint-naming.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-core-docs/www/eng-standards-constraint-naming.html,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/acs-core-docs/www/eng-standards-constraint-naming.html 17 Oct 2001 20:39:25 -0000 1.2 +++ openacs-4/packages/acs-core-docs/www/eng-standards-constraint-naming.html 2 Feb 2002 03:47:32 -0000 1.3 @@ -1,31 +1,124 @@ - -7. Constraint naming standard

Home : Documentation : Part III. For ACS Developers : 6. Engineering Standards : 7. Constraint naming standard 

7. Constraint naming standard

Table of Contents

7.1. The Big Picture
7.2. Abbreviations
7.3. Format of constraint name
7.4. Example
7.5. Why it's good to name primary keys
7.6. Naming not null constraints is optional...

By mbryzek@arsdigita.com

7.1. The Big Picture

+ + + + +Constraint naming standard + + + + + + + + +

+
+

+Constraint naming standard

+ +
+

+The Big Picture

+

Constraint naming standard is important for one reason: The SYS_* name oracle assigns to unnamed constraints is not very understandable. By correctly naming all contraints, we can quickly associate a particular constraint with our data model. This gives us two real advantages: -

  • We can quickly identify and fix any errors.

  • We can reliabily modify or drop constraints

-Why do we need a naming convention? +

+
    +
  • We can quickly identify and fix any errors.

  • +
  • We can reliabily modify or drop constraints

  • +
+

+

Why do we need a naming convention?
Oracle limits names, in general, to 30 characters, which is hardly enough for a human readable constraint name. -

7.2. Abbreviations

+

+
+
+

+Abbreviations

+

We propose the following naming convention for all constraints, with the following abbreviations taken from Oracle Docs at http://oradoc.photo.net/ora81/DOC/server.815/a67779/ch4e.htm#8953. Note that we shortened all of the constraint abbrevations to two characters to save room. -

Constraint typeAbbreviation
references (foreign key)fk
uniqueun
primary keypk
checkck
not nullnn

7.3. Format of constraint name

+

+
++++ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Constraint typeAbbreviation
references (foreign key)fk
uniqueun
primary keypk
checkck
not nullnn
+
+
+

+Format of constraint name

+

<table name>_<column_name>_<constraint abbreviation> -

+

+

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: -

  1. Abbreviate the table name with the table's initials (e.g. users -> u and users_contact -> uc). -

  2. Truncate the column name until it fits.

+

+
    +
  1. Abbreviate the table name with the table's initials (e.g. users -> u and users_contact -> uc). +

  2. +
  3. Truncate the column name until it fits.

  4. +
+

If the constraint name is still too long, you should consider rewriting your entire data model :) -

Notes:

  • If you have to abbreviate the table name for one of the constraints, abbreviate it for all the constraints

  • If you are defining a multi column constraint, try to truncate the two column names evenly

7.4. Example

+

+

Notes:

+
    +
  • If you have to abbreviate the table name for one of the constraints, abbreviate it for all the constraints

  • +
  • If you are defining a multi column constraint, try to truncate the two column names evenly

  • +
+ +
+

+Example

+
 create table example_topics (
        topic_id    integer
 		   constraint example_topics_topic_id_pk
@@ -49,11 +142,17 @@
        constraint cne_example_id_one_line_unq unique(example_id, one_line_description)
 );
 
-

7.5. Why it's good to name primary keys

+ +

+
+

+Why it's good to name primary keys

+

Naming primary keys might not have any obvious advantages. However, here's an example where naming the primary key really helps (and this is by no means a rare case! -

+

+
 SQL> set autotrace traceonly explain;
 
 
@@ -67,16 +166,53 @@
    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 + +

+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? -

7.6. Naming not null constraints is optional...

+

+
+
+

+Naming not null constraints is optional...

+

ArsDigita is split on whether or not we should be naming not null constraints... So, if you want to name them, please do so and follow the above naming standard. But, naming not null constraints is not a requirement at ArsDigita. -

-About Naming the not null constraints -

-Though naming "not null" constraints doesn't help immeditately in error +

+

+

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 +"Cannot insert null value into column"), we recommend naming not null constraints to be consistent in our naming of all constraints. -

($Id$)

+

+

($Id$)

+
+
+ + +