Quote:
Originally posted by ser_rom
Hello and thank you very much for your help.
I need some documents to format my code SQL. Example:
How can I call a Foreign key?. FK_...
And an Index?. IX_....
I need a document which explain all.
Thanks a lot.
SRR.
|
You can name them however you like, though of course you should have a standard. Many Oracle designers use Oracle Designer to create databases, and adopt its default naming conventions as standard. These are:
1) Every table has an "alias" of around 3 characters, e.g. "EMP" for EMPLOYEE, "DPT" for DEPARTMENT.
2) Primary keys are named EMP_PK, DPT_PK
3) Foreign keys are named EMP_DPT_FK
4) Indexes on foreign keys are named EMP_DPT_FK_I
5) Unique constraints are named EMP_UK1, EMP_UK2
It seems logical then to name other indexes with a "_I" suffix also, e.g. EMP_SURNAME_I.
Trigger names are user defined. Again, it seems logical to continue to use table aliases in their names, and to identify the type of trigger in the name, e.g. EMP_BIUR (Before Insert or Update for each Row).
Package names are user defined. It's quite common to use a "_PKG" suffix. If the package is "about" a table then the name might be e.g. EMP_PKG.
Procedures within packages are generally named in the form verb_noun e.g. hire_employee, calculate_bonus
Functions within packages are generally named in the form of a noun representing the return value e.g. department_headcount, total_commission.
(With very few exceptions, ALL procedures and functions should be in packages).
Check constraints are often named like EMP_HIRE_DATE_CHK, EMP_SALARY_CHK.
Have I missed anything?
I'm sure if you search the internet for "Oracle naming standards" you will find some alternatives - the point is, there is no "official" standard that everyone in the world follows.