Naming Conventions For Oracle Tables
Naming Conventions For Oracle Tables
Common rules
1. Only letters, numbers, and the underscore are allowed in names. Although Oracle
allows $ and #, they are not necessary and may cause unexpected problems.
2. All names are in UPPERCASE. Or at least of no importance which case. Ignoring
this rule usually leads referencing to tables and columns very clumsy because all names
must be included in double quotes.
3. The first character in the name must be letter.
4. Keep the names meaningful, but in the same time don't use
long_names_describing_every_single_detail_of_particular_object.
Tables
1. Table names are in plural form, for example, persons, materials, addresses. If
table name contains more than one word, they are separated with underscore in form
{name1}_{name2}. Only the last one is in plural, for example person_addresses.
2. All tables have 3 or 4 character long aliases that are unique in a schema. Aliases
are not directly used in name of table, but they are used to create column names. For
example, persons - prs, materials - mat, addresses - adr.
3. Sometimes it is useful to distinguish some logical parts of an application.
Therefore prefixes are used in table names. For example, sec_users, sec_roles,
sec_rights all are related to security subsystem.
Columns (for tables)
1. All columns are in form {alias}_{colname}. For example prs_id, prs_name,
prs_adr_id, adr_street_name. This guarantees that column names are unique in a schema,
except denormalized columns from another table, which are populated using triggers or
application logic.
2. All columns are in singular. If you think you need a column name in plural think twice
whether it is the right design? Usually it means you are including multiple values in the
same column and that should be avoided.
3. All tables have surrogate primary key column in form {alias}_id, which is the
first column in the table. For example, prs_id, mat_id, adr_id.
Keys, Constraints
1. All primary keys are named {alias}_pk. For example prs_pk.
2. All foreign keys are named {alias1}_{alias2}_fk. For example prs_adr_fk.
3. If there are more than one foreign key to another table then foreign keys are
named {alias1}_{alias2}_{meaningful_name}_fk. For example, prs_adr_curr_fk,
prs_adr_prev_fk.
4. All unique keys are named {alias}_{meaningful_name}_uk. For example,
mat_typename_uk which is on columns mat_name and mat_type.
5. All check constraints are named {alias}_{meaningful_name|number}_ck. For
example, mat_type_ck which is on column mat_type.
Indexes
1. Every index on foreign key is in form {alias1}_{alias2}_fk_i. For example,
prs_adr_fk_i.
2. Every index on one column is in form {full_column_name}_i. For example,
mat_name_i.
3. Every index on two or more columns is in form {alias}_{meaningful_name|
number}_i. For example, mat_1_i, mat_2_i.
Sequences
1. Every table has its own sequence in form {alias}_seq. It and ONLY it is used to
populate corresponding primary key column. If an application needs some precreated data,
remember to create sequences with start value greater than max value of corresponding
column. For example, prs_seq, mat_seq.
Views
1. View names are prefixed with vw_.
2. View names are in plural form, for example, vw_students. If view name contains
more than one word, they are separated with underscore in form vw_{name1}_{name2}.
Only the last one is in plural, for example vw_student_addresses.
3. All views have 3 or 4 character long aliases that are unique in a schema. It is
necessary only in case the view contains some complex derived columns from underlying
tables.
There must be at least some standard developing application and schema. Not
obligatory this one. So I think every approach is good enough if it isn't chaotic and
you are satisfied with it.
References
I got some ideas from Joe Garrick's Database Programming Corner - Database Object
Naming Conventions. The link is now broken and I cannot find it any more. But it was
mostly for Access and SQL Server.