The main reason to adopt a naming convention is so you and others can easily understand the structure. Naming conventions should produce concise, legible, unambiguous, and consistent names. Naming conventions should clarify instead of confuse; the strictest adherence to naming conventions will result in ridiculous names.
Who should adopt a naming convention? The following should:
It is common to have names composed of different parts. Here are some common syntaxes:
[prefixes]{tag}[BaseName][Qualifiers]
[tagprefixes][tag][PREFIXES_]{BaseName}[Qualifiers][_SUFFIXES]
Limit the length. Shorter is better. Here are actual DBMS maximum lengths for column names:
Use only ASCII letters, numbers, and underscore (_). The first character should be a letter since some DBMSs don't accept anything else as the first letter. Here are some details of the actual DBMS character restrictions:
., !, `, [, and ]._, and $. First letter could be a digit (but why bother?). Last character cannot be a space (but why bother?)._, @, or #. If the name includes other characters then it must be delimited. No spaces.Avoid abbreviations. If an abbreviation must be used, then avoid ambiguous or inconsistent abbreviations, and try to use the same abbreviation throughout the databases. EG:
Here are some pretty common database abbreviations from the University of Arizona:
| Name | Abbreviation | Description |
|---|---|---|
| Amount | Amt | A monetary value. |
| Category | Catgy | A specifically defined division or subset in a system of classification in which all items share the same concept of taxonomy. |
| Code | Cd | A combination of one or more numbers, letters, or special characters which is submitted for a specific meaning (includes Status and Abbreviation). |
| Date | Dt | The notion of a specific period of time. |
| Description | Descn | A word or phrase which interprets an abbreviation, code or other shortened term so as to make it more understandable to users (i.e., Arizona is the description of the abbreviation AZ). |
| Identifier | Idfyr | A combination of one or more integers, letters, special characters which designate a specific object/entity, but has no readily definable meaning (includes Designator, Key, Number). |
| Indicator | Indcr | An identifier which has a domain of only 2 states, such as: Y/N, ON/OFF,TRUE/FALSE, 0/1, etc. |
| Name | Nm | The designation of an object/entity expressed in a word or phrase. |
| Number | Nbr | A value which is not for the purpose of measuring a quantity or serving as a counter, but which is usually a numeric value (it may contain non-numeric characters, such as a Product Number, PO Number, etc.). It is distinguishable in that arithmetic operations are not usually carried out on it. |
| Quantity | Qty | A non-monetary value. (Includes: Average, Balance, Deviation, Factor, Index, Level, Mean, Median) |
| Rate | Rt | A quantity, amount or degree of something in relation to units of something else. (Includes: Factor, Frequency, Percent, Scale) |
| Text | Txt | An unformatted character string, generally in the form of words. (Includes: Abbreviation, Comments) |
| Time | Tm | A notion of a specified chronological point within a period. |
Make names readable. A rule of thumb is that you should be able to read the name to someone over the phone without having to spell out portions. Note that too many abbreviations violates this rule.
Use mixed case, especially to distinguish between "words" within a part of a name. EG: ProductName. Some folks like to use underscore (_) to separate parts of a name. EG: HR_Status and HR_Ballots. I personally find that practice annoying. Plus there are more creative uses for the underscore (see Tables below).
It has been suggested by the Leszynski and Reddick to use the following prefixes to indicate the status of certain database objects. Note that z is used to make the items appear at the top of lists. I suggest adding the developer's initials or name after each of these prefixes so we know who to contact about the status of these items.
zz denotes objects you've deserted but may want to keep in the database for awhile for future reference or use. EG: zzvueFoo. zt denotes temporary objects. EG: ztvueFoo.zs denotes system objects. EG: zsvueFoo. System objects are items that are part of the development and maintenance of an application not used by end users, such as error logs, development notes, documentation routines, relationship information, and so on._ denotes objects under development. EG: _vueFoo. An underscore before an object name sorts to the top of the database container to visually remind you that it needs attention. Remove the underscore when the object is ready to use and it will sort normally. Note that I prefer to use a_, aa, or a0 to stick with the rule of thumb of using a letter as the first character.Use nouns for most objects. EG: vueEmployee. Use verbs (EG: Multiply()) or verb and noun combinations (EG: AddDog()) for objects that do things such as functions or stored procedures. If you use verb and noun combinations, be consistent with the order, i.e. use NounVerb() or VerbNoun(). The latter is closer to English and is good for sorting a list according to the action taken, but the former is better for sorting a list of functions according to the object they work on.
This shouldn't need to be said, but avoid naming anything with a reserved word.
dbFinance. This automatically avoids reserved words.ILCounties and ILCities for the Illinois databases.Products table. I prefer singular because singular is usually shorter and it sounds better when you qualify columns. EG: Product.Name='cup' sounds better than Products.Name='cup'.OrderProduct. Some folks like to use and underscore to emphasize the bridge. EG: Order_Product. This can produce really long names so you may want to follow the convention where the name of a join table is composed of abbreviations of the tables it joins. EG: OrdPro or Ord_Pro. It is also a good to consistently concatenate the table in bridge tables in alphabetical order. EG: Order_Product instead of Product_Order. If the bridge table bridges many tables, then it give its own custom name. EG: Crossroad.Product_New.Product is a look up table to the ProductOrder table, but Product is a foreign table to the Supplier table. Because of this, only dedicated reference tables (look up tables that change infrequently) can be given a special prefix. EG: ref or LU or zref_ or ZLU, as in zrefUSStates.Product.Pr_ID or Order.Pr_ID. Some people actually prefer to use the abbreviated version of the table name for the table name itself, especially if their DBMS only allow shorter names. EG: Pr.Pr_ID. Abbreviations provide brevity but they also tend to form code that looks very much like gibberish.t, tbl, or tbl_) because tables are clearly identifiable as tables from context: they follow the FROM keyword or are used to qualify columns. However such a prefix has some uses:HR_ and SL_ for Human Resources and Sales.appRL_ for the Rush Licensing application.y1999_ or _y1999.temp because otherwise you'll inevitably forget that it was supposed to be a temporary table.TableID or ID. EG: OrganizationID or ID. Do not use ID if the column is not an integer or the field has a common industry name. EG: SSN._PK, especially if the primary key is composed of multiple columns. EG: Car.Make_PK and Car.Model_PK. I personally prefer to make give each table with a single-column primary key and avoid the use of _PK.ForeignTableID or ForeignTableID_FK. EG: ProductOrder.ProductID or ProductOrder.ProductID_FK is a qualified foreign key in the ProductOrder table for the foreign table Product. I personally don's use the _FK suffix since a column name that isn't the primary key but ends in ID is most likely a foreign key.PrOr.PrID or PrOr.PrID_FK. OrganizationID.Name or TableName if applicable. For a table of people, it may be worthwhile to have Name in addition to FirstName and LastName.Note, DateActivated, DateDeactivated.{LookUpTable_}{ForeignTable_}{ForeignKey}_FK.
ProductOrder.ProductOrder_ProductID_FKProductOrder.ProductOrder_ProductIDProductOrder.ProductOrder_PrID_FKProductOrder.ProductOrder_PrIDProductOrder.PrOr_ProductID_FKProductOrder.PrOr_ProductIDProductOrder.PrOr_PrID_FKProductOrder.PrOr_PrIDProductOrder.ProductID_FKProductOrder.ProductIDProductOrder.PrID_FKProductOrder.PrIDc or col) since, they are clearly identifiable as columns from context.strDescription. This may be useful but can also be tedious and you should always know for certain the specifics of the data type of a column anyway. See SQL Statement Variables for commonly used tags indicating data type.date (for date), time (for time), dtm or stamp (for date and time), pub (for public notes), etc.{TableIndexed}{ColumnsIndexed}_IDX[p][u][c], where p is primary key, u is unique, and c is clustered. EG: ProductName_IDXc, indicates that this is a clustered index on the Name column of the Product table.v, view, or vue for views and q or qry for queries.flt for filter or lkp for look up. There are many suggestions for this that can be standardized across companies:HR_ and SL_ for Human Resources and Sales.INSCustomerInfo or CustomerInfo_INS. A very similar idea is to use the primary table affected combined with the general function. EG: CustomerInsert.sp, sp_, stp, s, p, or proc) because these are always clearly identifiable from context: they follow the EXECUTE keyword. Avoid the sp_, dt_, and xp_ tags in particular because they are used by SQL Server and it also makes SQL Server look in the master database first. However a prefix is convenient if you are discussing a stored procedure in comments.INS for insert or ARC for Archive.HR_ and SL_ for Human Resources and Sales.appRL_ for the Rush Licensing application.r or rpt prefixes.GetConeVolume or ConeVolumeGet.F, f, fun, or fnc. It often easy to identify a function from context. Avoid using fn_ because that is how SQL Server prefixes its functions.dbo.FRunMe() is local to the database where as master.dbo.FRunMe() is available in all databases.str for string or tbl for table.HR_ and SL_ for Human Resources and Sales.appRL for the Rush Licensing application.TableOfTrigger_TGR[i][u][d], where i is insert, u is update, and d is delete. EG: Product_TGRi, indicates that this trigger fires when an attempt is made to insert into the Product table.TableOfDefault_[Description]_DEF for a default or TableOfRule_[Description]_RUL for a rule.In SQL Server, variables follow this syntax:
@VariableName. Local variables or parameters start with an @.@@VariableName. Global variables and some Transact-SQL functions start with a double-@.It is worth while to prefix variable names with data type. Here is a table of common prefixes:
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
It may also be worth while to use these various name modifiers:
p for parameter. EG: pintStart.rp for return parameter. EG: rpintFinish.a or_a for array. EG: astrNames.ia or_ai for an item in an array or collection. EG: strWinner = astrNames(iastrNames).dbFinance_200703070948.bak.Listed in no particular order are sources referenced while making this page:
Charles Simonyl is credited with the Hungarian naming convention of prefixing base names with lower case tags such as strObject.
Page Modified: (Hand noted: 2007-10-06 05:57:36Z) (Auto noted: 2007-11-17 06:47:55Z)