Database Reference
In-Depth Information
Naming Stored Procedures
Naming stored procedures is simple; we preface them with “prc_” fol-
lowed by a descriptive name. Stored procedures can often update many ta-
bles in one shot, so again be careful not to let the name get too long. One
tip: If you don't like our prefix “prc_” and you would rather use your own,
that is fine, but we caution against using “sp_.” That is the prefix that
Microsoft uses in SQL Server for system stored procedures, and using
“sp_” can lead to confusion.
Naming User-Defined Functions
User-defined functions are named in the same manner as stored proce-
dures. The prefix we use for UDFs is “udf_.” SQL Server has several built-
in functions that use “fn_” as the prefix, so you should avoid that as an
alternative.
Naming Triggers
Triggers present an interesting problem when it comes to naming. We still
use a prefix, in this case “trg_,” but triggers are also attached to a specific
table and tie to a specific statement or statements that run against that
table. Triggers can be configured to run after an insert, update, or delete
or instead of an insert, update or delete. You can even define a single trig-
ger to run on multiple conditions such as after an insert and after an up-
date on the same table. Although it would be nice to use a descriptive
name such as trg_upd_tbl_customer, it can get a little messy if the trigger
runs in response to more than one condition. Imagine the name for a
trigger that fires on delete, insert, and update on a table name that con-
tains customer history; it would be something like trg_ins_upd_del_tbl_
customer_history. That is just ridiculous.
How do we solve this problem? We name triggers in the same way we
name stored procedures: a “trg_” prefix followed by a descriptive name.
Beyond that, we are OK with looking up the detail on triggers when we are
working with them.
Naming Indexes
Indexes are named in a similar manner as the other objects. We start with
the prefix “idx_” and follow with a description of the index. For example,
an index on the customer table's first_name and last_name columns could
Search WWH ::




Custom Search