Jason Mauss' Blog Cabin

Because someone's got to do the dirty work

Blog-Flair

Blogroll

Links

DevCampus Database Naming Conventions

Database Naming Conventions Version 1.1
Last Revised May 13, 2004 by Jason Mauss

The main goal of adopting a naming convention for database objects is so that you and others can easily identify the type and purpose of all objects contained in the database. The information presented here serves as a guide for you to follow when naming your database objects. When reading these rules and guidelines remember that consistent naming can be the most important rule to follow. Keep in mind that  following the guidelines as outlined in this document can still produce long and cryptic names, ultimately, your unique situation will dictate the reasonability of your naming convention. The goal of this particular naming convention is to produce practical, legible, concise, unambiguous and consistent names for your database objects.

While most databases contain more types of objects than those discussed here (User Defined Types, Functions, Queries, etc.), the 7 types of objects mentioned here are common among all major database systems. Think of this as a generic DBMS-neutral guide for naming your objects.

The following types of database objects are discussed here:

  1. Tables
  2. Columns (incl. Primary, Foreign and Composite Keys)
  3. Indexes
  4. Constraints
  5. Views
  6. Stored Procedures
  7. Triggers

ALL DATABASE OBJECTS

  • Limit the name to 30 characters (shorter is better)
  • Use only letters or underscores (try to avoid numbers)
  • Try to use underscore characters as little as possible. PascalCase notation achieves the same word separation without them.
  • Use a letter as the first character of the name. (don't start names with underscores)
  • Avoid abbreviations (can lead to misinterpretation of names)
  • Avoid acronyms (some acronyms have more than one meaning eg. "ASP")
  • Makes the name readable (they shouldn't sound funny when read aloud)
  • Avoid using spaces in names even if the system allows it.

1. TABLES
When naming your database tables, give consideration to other steps in the development process. Keep in mind you will most likely have to utilize the names you give your tables several times as part of other objects, for example, procedures, triggers or views may all contain references to the table name. You want to keep the name as simple and short as possible. Some systems enforce character limits on object names also. For example, in Oracle you are limited to about 30 characters per object.

Rule 1a (Plural Names) - Table names should be plural, for example, "Customers" instead of "Customer". This rule is applicable because tables are logical collections of one or more entities as records - just like collection classes are logical collections of one or more objects. If you were to first draw an abstract data model like a NIAM/ORM model, you might have singular entity names like "Customer" or "User" but, they should be changed to the plural form when building the actual tables. For table names with multiple words, only the last word should be plural, for example, "UserRoles" and "UserRoleSettings".

Rule 1b (Prefixes) - Used correctly, table prefixes can help you organize your tables into related groups or distinguish them from other unrelated tables. Used poorly, they can cause you to have to type a lot of unnecessary characters. We'll discuss what not to do first. Do not give your table names prefixes like "tbl" or "TBL_" as these are just redundant and unnecessary. It will be obvious which names are the table names in SQL statements because they will always be proceeded by the FROM clause of the SELECT statement. Not all prefixes are bad. In some cases, your tables might be sharing a schema/database with other tables that are not related in any way. In this case, it is sometimes a good idea to prefix your table names with some characters that group your tables together. For example, for a healthcare application you might give your tables an "Hc" prefix so that all of the tables for that application would appear in alphabetized lists together. Note that even for the prefix, use Pascal Case. This is discussed in Rule 1c. Do not use underscores in your prefixes, which is discussed in more depth in Rule 1d. The last kind of prefix that is acceptable is one that allows you to group logical units of tables. A plausible example could entail a large application (30 to 40+ tables) that handled both Payroll and Benefits data. You could prefix the tables dealing with payroll with a "Pay" or "Prl" prefix and give the tables dealing with benefits data a "Ben" or "Bfts" prefix. The goal of both this prefix and the aforementioned shared schema/database prefix is to allow you to group specific tables together alphabetically in lists and distinguish them from unrelated tables. Lastly, the shared schema/database prefix is a higher grouping level and comes first in the name, for example, "HcPayClients" not "PayHcClients".

Rule 1c (Notation) - For all parts of the table name, including prefixes, use Pascal Case. Using this notation will distinguish your table names from SQL keywords (all capital letters). For example, "SELECT CustomerId_Pk, CustomerName FROM MyAppGroupTable WHERE CustomerName = '%S'" shows the notation for the table name distinguishing it from the SQL keywords used in the query. PascalCase also reduces the need for underscores to visually separate words in names.

Rule 1d (Special Characters) - For table names, underscores should not be used. The underscore character has a place in other object names but, not for tables. Using Pascal Case for your table name allows for the upper-case letter to denote the first letter of a new word or name. Thus there is no need to do so with an underscore character. Do not use numbers in your table names either. This usually points to a poorly designed data model or irregularly partitioned tables. Do not use spaces in your table names either. While most database systems can handle names that include spaces, some systems require you to add more characters around the name when referencing it (like [table name] for example) which goes against the rule of keeping things as short and simple as possible. If you are developing in a non-english language, do not use any of that language's special characters.

Rule 1e (Abbreviations) - Avoid using abbreviations if possible. Use "Accounts" instead of "Accts" and "Hours" instead of "Hrs". Not everyone will always agree with you on what your abbrevations stand for - and - this makes it simple to read and understand for both developers and non-developers. This rule can be relaxed for junction table names (See Rule 1f). Do not use acronyms.

Rule 1f (Junction a.k.a Intersection Tables) - Junction tables, which handle many to many relationships, should be named by concatenating the names of the tables that have a one to many relationship with the junction table. For example, you might have "Doctors" and "Patients" tables. Since doctors can have many patients and patients can have many doctors (specialists) you need a table to hold the data for those relationships in a junction table. This table should be named DoctorsPatients". Since this convention can result in lengthy table names, abbreviations sometimes may be used at your discretion.

2. COLUMNS - (incl. PRIMARY, FOREIGN, AND COMPOSITE KEYS)
When naming your columns, keep in mind that they are members of the table, so they do not need the any mention of the table name in the name. The primary key field is typically the only exception to this rule where including the table name is justified so that you can have a more descriptive field name than just "Id". "CustomerId" is acceptable but not required. Just like with naming tables, avoid using abbreviations, acronyms or special characters. All column names should use Pascal Case to distinguish them from SQL keywords (all upper case).

Rule 2a (Identity Primary Key Fields) - For fields that are the primary key for a table and uniquely identify each record in the table, the name should simply be “Id“ since, that's what it is - an identification field. This name also maps more closely to a property name like “Id“ in your class libraries. Another benefit of this name is that for joins you will see something like
      "Customers JOIN Orders ON Customer.Id = Orders.CustomerId“
which allows you to avoid the word “Customer“ again after the Customer table.

Rule 2b (Foreign Key Fields) - Foreign key fields should have the exact same name as they do in the parent table where the field is the primary key - with one exception - the table name should be specified. For example, in the Customers table the primary key field might be "Id". In an Orders table where the customer id is kept, it would be "CustomerId". There is one exception to this rule, which is when you have more than one foreign key field per table referencing the same primary key field in another table. In this situation, it might be helpful to add a descriptor before the field name. An example of this is if you had an Address table. You might have another table with foreign key fields like HomeAddressId, WorkAddressId, MailingAddressId, or ShippingAddressId. 

Rule 2c (Composite Keys) - If you have tables with composite keys (more than one field makes up the unique value) then instead of just “Id“ you should use a descriptor before the “Id“ characters. Two fields like “ModuleId“ and “CodeId“ might make up the composite key, for example. If you don't see an “Id“ column in the table - you'll know that a composite key is used to uniquely identify records.

Rule 2d (Prefixes) - Do not prefix your fields with "fld_" or "Col_" as it should be obvious in SQL statements which items are columns (before or after the FROM clause). Including a two or three character data type prefix for the field is optional and not recommended, for example, "IntCustomerId" for a numeric type or "VcName" for a varchar type. However, these data type abbreviations are DBMS specific and are outside the scope of this document.

Rule 2e (Data Type Specific Naming) - Boolean fields should be given names like "IsDeleted", "HasPermission", or "IsValid" so that the meaning of the data in the field is not ambiguous. If the field holds date and/or time information, the word "Date" or "Time" should appear somewhere in the field name. It is sometimes appropriate to add the unit of time to the field name also, especially if the field holds data like whole numbers ("3" or "20"). Those fields should be named like "RuntimeHours" or "ScheduledMinutes".

3. INDEXES
Since indexes are always related to a table or view, it makes the most sense to use the name of the table or view, as well as the column(s) they index, in the index name, along with some characters that specify the type of index it is. This naming convention also allows you, if looking at a list of indexes, to see the indexes ordered by table, then column, then index type.

Rule 3a (Naming Convention) - The naming convention for indexes follows this structure:

     {TableName}{ColumnsIndexed}{U/N}{C/N}

where "U/N" is for unique or non-unique and "C/N" is for clustered or non-clustered. This naming convention is unique among database objects, so adding characters to denote it being an index, like "idx" is not necessary. The naming convention alone is self-documenting and indentifies it as an index. For indexes that span multiple columns, concatenate the column names. "ProductsIdUC" indicates a unique, clustered index on the Id column of the Products table. OrderDetailsOrderIdCustomerIdNN" indicates a non-unique, non-clustered index on the OrderId and CustomerId columns in the OrderDetails table. Since this name is rather lengthy with both "OrderId" and "CustomerId" spelled out, they could be shortened to OrdId and CustId. However, notice that by using Pascal Case, thus not needing to use underscores, it is possible to keep the name of a complex index to about 30 characters.
    
Rule 3b (Prefixes and Suffixes) - Avoid putting a prefix like "idx" or "IDX_" before your indexes. This is not necessary due to the naming convention discussed in Rule 3a. A suffix of "_idx" or "IDX" is not necessary either for the same reason.

4. CONSTRAINTS
Constraints are at the field/column level so the name of the field the constraint is on should be used in the name. The type of constraint (Check, Referential Integrity a.k.a Foreign Key, Primary Key, or Unique) should be noted also. Constraints are also unique to a particular table and field combination, so you should include the table name also to ensure unique constaint names across your set of database tables.

Rule 4a (Naming Convention) - The naming convention syntax for constraints looks like this:

     {constraint type}{table name}_{field name}

Examples:
1. PkProducts_Id  - primary key constraint on the Id field of the Products table
2. 
FkOrders_ProductId    - foreign key constraint on the ProductId field in the Orders table
3. CkCustomers_AccountRepId - check constraint on the AccountRepId field in the Customers table

The reason underscores are used here with Pascal Case notation is so that the table name and field name are clearly separated. Without the underscore, it would become easy to get confused about where the table name stops and the field name starts.

Rule 4b(Prefixes) A two letter prefix gets applied to the constraint name depending on the type
     Primary Key: Pk
     Foreign Key: Fk
     Check: Ck
     Unique: Un

5. VIEWS
Views follow many of the same rules that apply to naming tables. There are only two differences (Rules 5a and 5b). If your view combines entities with a join condition or where clause, be sure to combine the names of the entities that are joined in the name of your view. This is discussed in more depth in Rule 5b.

Rule 5a (Prefixes) - While it is pointless to prefix tables, it can be helpful for views. Prefixing your views with "Vw" or "View" is a helpful reminder that you're dealing with a view, and not a table. Whatever type of prefix you choose to apply, use at least 2 letters and not just "V" because a prefix should use more more than one letter or its meaning can be ambiguous.

Rule 5b (View Types) - Some views are simply tabular representations of one or more tables with a filter applied or because of security procedures (users given permissions on views instead of the underlying table(s) in some cases). Some views are used to generate report data with more specific values in the WHERE clause. Naming your views should be different depending on the type or purpose of the view. For simple views that just join one or more tables with no selection criteria, combine the names of the tables joined. For example, joining the "Customers" and "StatesAndProvinces" table to create a view of Customers and their respective geographical data should be given a name like "VwCustomersStatesAndProvinces". For a view that is more like a report, a name like "VwDivisionSalesFor2004" might make more sense.

6. STORED PROCEDURES
Unlike a lot of the other database objects discussed here, stored procedures are not logically tied to any table or column. Typically though, stored procedures perform one of the CRUD (Create, Read, Update, and Delete) operations on a table, or another action of some kind. Since stored procedures always perform some type of operation, it makes sense to use a name that describes the operation they perform. Use a verb to describe the type of operation, followed by the table(s) the operations occur on.

Rule 6a (Prefixes or Suffixes) - The way you name your stored procedures depends on how you want to group them within a listing. If you'd like to group them by the type of CRUD operation they perform, then prefix the name with "Create", "Get", "Update" or "Delete". Using this kind of prefix will, for example, group all of your "Create" procedures together since they will all start with the Create prefix, like "CreateProductInfo" or "CreateOrder". If instead, you would like to have your procedures ordered by the table they perform a CRUD operation on, adding "Create, Get, Update, or Delete" as a suffix will do that for you. For example, "ProductInfoCreate" or "OrdersCreate". If your procedure returns a scalar value, or performs an operation like validation, you should not use a CRUD prefix or suffix. Instead use the verb and noun combination. For example, "ValidateLogin"

Rule 6b (Grouping Prefixes) - If you have many stored procedures, you might want to consider using a grouping prefix that can be used to identify which parts of an application the stored procedure is used by. For example, a "Prl" prefix for Payroll related procedures or a "Hr" prefix for Human Resources related procedures can be helpful. This prefix would come before a CRUD prefix (See Rul 6a).

Rule 6c (Bad Prefixes) - Do not prefix your stored procedures with something that will cause the system to think it is a system procedure. For example, in SQL Server, if you start a procedure with "sp_", "xp_" or "dt_" it will cause SQL Server to check the master database for this procedure first, causing a performance hit. Spend a little time researching if any of the prefixes you are thinking of using are known by the system and avoid using them if they are.

7. TRIGGERS
Triggers have many things in common with stored procedures. However, triggers are different than stored procedures in two important ways. First, triggers don't exist on their own. They are dependant upon a table. So it is wise to include the name of this table in the trigger name. Second, triggers can only execute when either an Insert, Update, or Delete happens on one or more of the records in the table. So it also makes sense to include the type of action that will cause the trigger to execute.

Rule 7a (Prefixes and Suffixes) - To distinguish triggers from other database objects, it is helpful to add "Trg" as a prefix or suffix. For example any of these combinations work: Trg_ProductsIns, ProductsInsTrg, Products_InsTrg, or InsProducts_Trg. As long as you include the table name, the operation that executes the trigger (Ins, Upd, or Del) and the "Trg" letters, it should be obvious to someone working with the database what kind of object it is. As with all conventions you use, pick one and remain consistent.

Rule 7b (Multiple Operations) - If a trigger handles more than one operation (both INSERT and UPDATE for example) then include both operation abbreviations in your name. For example, "Products_InsUpdTrg" or "TrgProducts_UpdDel"

Rule 7c (Multiple Triggers) - Some systems allow multiple triggers per operation per table. In this case, you should make sure the names of these triggers are easy to distinguish between. For example "Users_ValidateEmailAddress_InsTrg" and "Users_MakeActionEntries_InsTrg".

Comments

TrackBack said:

# May 10, 2004 11:42 PM

TrackBack said:

# May 10, 2004 11:45 PM

Alex Papadimoulis said:

Jason,

Good article, but I'll have to disagree with you on the _Pk, _Fk business. It's not only superflous, but it will cause a major headache when keys change. And they sure do. Consider going from a straight text field (let's say "Status") to a constrained lookup table, now you're stuck with changing the column name (to "Status_fk") or having an inconsitant naming convention. Ditto for the column datatype prefix, as those can change too (eg, intQuantity becomes a float because they need partial returns, or something).

And kudos for saying "No" to the "tbl" prefix! It's very frusterating to have view's named tblWhatever and tables named vwSomething.

-- Alex
# May 11, 2004 1:08 AM

Joel Ross said:

Jason,

Overall, great job. I just got done reviewing a database, and having something like this ahead of time would have been awesome.

I do agree with Alex above though. I don't like the _Pk and _Fk in the columns, because they can change. I would also say there are exceptions to the Foreign key always being named the same as the field in the lookup table. For example, if I have a table of addresses, my profile may have a mailing, shipping and billing address associated with them. In some cases it might make sense to have a many to many table between them, but in some cases it makes sense to just have three columns for MailingAddressId, ShippingAddressId and BillingAddressId, where the PK in the Addresses table might be AddressId. I would agree it should CONTAIN the name of the original field, but would add that it could have a descriptor in front of it.

I'll be using this as a reference whenever I do database design work from now on though! Great job!

Joel
# May 11, 2004 12:46 PM

Jason Mauss said:

Thanks for the feedback Joel - that's actually a really good point you make about multiple foreign keys mapping to the same primary key. I think I'll make another rule stating that it's OK to add a descriptor in front of the Foreign key field name - I actually think I've also done that before myself so, it must've slipped my mind.

Can someone give me an example of primary or foreign key fields needing to change though? That doesn't happen very often, if ever on the databases I've designed or worked with. Maybe I just can't envision the situation that would cause that.
# May 11, 2004 12:52 PM

Joel Ross said:

Primary keys, maybe not. Foreign keys changing is unlikely, but I can see them being added - the example of a status being hard coded into the application (right or wrong) and later being added to a lookup table. I would rather just call the field status, and leave it alone.

I guess if you do your due diligence up front, you would be OK. The keys shouldn't change, and you should build all of your lookups into the database.

My biggest thing is that I just don't like typing underscores! Plus, (at least for primary keys) if the key is the singular table name with Id added, I don't see a need for the _Pk, and if it's another type of Id, then it's a foreign key. If it's a composite key, most likely it's a junction table, so you know you are dealing with composite keys. Maybe it's just me. Plus, it looks better without the underscores if you use typed datasets!

Just my two cents (again).

Joel
# May 11, 2004 1:02 PM

Gareth Rowell said:


Ommitting the name prefixes makes sense when using SQL but what about when you are using PL/SQL, VBA, perl and all the other irregularities in the world?

Thnx for addressing the topic!!
# May 11, 2004 1:32 PM

Jason Mauss said:

Gareth,
Are you talking about writing stored procs and data access code? For stored procs (PL/SQL or TSQL) it should be obvious what the entity is you're working with (field or table or other) by where it appears in the SQL statement. If you're writing VBA or Perl you really shouldn't be embedding SQL within your code anyway, it's not a good idea. I typically use an external XML file to store all my queries, which I populate doing just copy and paste from a tool like Query Analyzer or TOAD. Then, outside of data access code, you should just be accessing properties of objects and not fields directly from DataSets or Recordsets.
# May 11, 2004 2:00 PM

TrackBack said:

# May 11, 2004 4:08 PM

TrackBack said:

# May 11, 2004 6:46 PM

Igor Anic said:

Good work, here are some comments:
I must disagree with inconsistent use of underscore. If you are trying to create rules your overall conventions (for all database objects) could not be: "Try to use ... as little as possible", the rule must be: "Do not use...". Later you could make exception to the rule but with the good reason. Using underscores in naming constraints is a bad decision.
When naming database column I'm traying to follow object paradigm, table is representing an object and columns are properties of that object. For example if you have an object name File then the file name is usually represented by the property Name: File.Name. It is not named FileName or File_Name or something like that. So I strongly agree with not using table names in column names. I follow the same logic for id-s, for the column which is unique identifier of the object I use the name ID (not the FileID). When that column is the foreign key in another table then I name it FileID (would be great to name it File.ID to stick with the object paradigm, but most DBMS will have extra requirements for that).
Naming ID columns is realy important because we are using them joins so it is important that thay look intuitive.
I'm using:
... File inner join Directory on File.ID = Directory.FileID ...
it looks to me little better than:
... File inner join Directory on File.FileID = Directory.FileID ...
but this has a lot of repeating information's:
... File inner join Directory on File.FileId_Pk = Directory.FileId_Fk ...

Igor
# May 12, 2004 3:27 AM

Jason Mauss said:

Yeah, I am starting to agree with you on that Igor - about just naming the primary or surrogate key "Id". See my comments on the blog entry that points to this article.
# May 12, 2004 3:33 AM

Mike Woodhouse said:

My general experience is that *any* standard is better than none (or four different, incompatible ones applied to the same database, as I struggle with at the moment*) and a good standard is (obviously) better yet.

I actually found little to quibble at, other than not liking having "Ck" as suffix in column names and prefix in constraints when it expands to different meanings. I know the context is different, but my poor old brain doesn't always remember to context-switch like it used to... ;-)

Would it not be more transparent to use "Ch" (or similar) for check constraints?

Mike

* but it's OK, we're fixing that: a new, "definitive" standard has been proposed (let's get back to the "tbl" prefix, yay!) and we're going to apply that to all new work. We're going to leave the existing mess as it is. My cup runneth over.
# May 12, 2004 5:19 AM

Jeff Gonzalez said:

I have to say that standard hurts my eyes. We do things in a completely different manner, but I agree with Mike, any standard is better than one.
# May 14, 2004 3:58 PM

Jason Mauss said:

Jeff - what about it hurts your eyes? What kind of standard do you employ? I'm very open to feedback on ways to improve the conventions for this.
# May 14, 2004 3:59 PM

TrackBack said:

# May 17, 2004 4:29 AM

Igor Anic said:

Dear Jason,
I mostly agree with your rules for naming tables, columns and stored procedures, but I see a lot of inconsistency in naming other object. For example for some objects you are suggesting prefix or suffix and for other don’t. For some you are suggestion use of the underline for others don’t. I would like to have stronger rules. This will also result in simpler and easier to remember rules. Here is my suggestion:

User prefixes for all except default database objects.
In my case default database object are tables and stored procedures.
Naming non-default database objects:

{prefix}{table name}_[{field name list}{description}{referenced table}]

Applied to an object:

Index: {idx | cidx | uidx}{table name}_field name[_{field name}...]
View: {vw}{table name}_{description}
PrimaryKey: {pk}{table name}
ForeignKey: {fk}{table name}_{referenced table name}
Check constraint: {ck}{table name}_{description}
Trigger: {trg}{table name}_{Ins | Upd | Del}

Samples:

Index: idxCustomers_FirstName_LastName
Unique index: uidxCustomers_Username
Clustered index: cidxCustomers_Username
View: vwCustomers_EastRegion
PrimaryKey: pkCustomers
ForeignKey: fkCustomers_Departments
Check constraint: ckCustomers_AccountRepID
Trigger: trgCustomers_InsUpd

Of course choosing prefixes is the matter of taste, as long as we are consistent during project.
What I'm trying to point is that we need a simple easy to remember overall rule for all objects.

Igor.
# May 21, 2004 6:54 AM

TrackBack said:

# June 1, 2004 5:56 PM

sadfas said:

sdfasdfasdfjleiaodsjfjlsaf
# June 3, 2004 4:58 AM

justin said:

Jason,
Here are some comments I have on your standard above. For a variation on the theme, check out my <A HREF="http://www.unc.edu/~jwatt/writings/naming_conventions.html">Essential Database Naming Conventions (and Style)</A>.
Justin


there are a number of good reasons to not pluralize table names:

consistency with primary key name:
table name: activity
primary key: activity_id

--rather than--

table name: activities
primary key: activity_id

consistancy/transparency with lookup table names:
table name: activity
lookup table: activity_type

--rather than--

table name: activities
lookup table: activity_types

more grammatical SQL:
SELECT activity.name
FROM activity
WHERE activity_id = 7;
(the select retrieves the name of a specific activity, whether or not the WHERE clause returns one or more rows. reading "activities.name" suggests a name for all activities.)

predictable alphabetical ordering of table names:
user
userRole

--rather than--

userRoles
users


There are also some good reasons to concatenate the table name on to the field name:

it avoids SQL namespace collisions
"activity_name" and "activity_order" rather than "name" and order"

it uniquely names every field name in the database, which is recommended for when using PHP, where retrieved field names become array keys to the values.

it maintains semantic transparency if you use table aliases in your SQL:
SELECT p.project_name, a.activity_name
FROM project p LEFT JOIN activity a ON p.project_id = a.project_id
WHERE p.project_name = "world domination"

--rather than--

SELECT p.name, a.name
FROM project p LEFT JOIN activity a ON p.id = a.id
WHERE p.name = "world domination"
# June 4, 2004 12:04 PM

David Kassa said:

I just wanted to say thanks for the great article! My office doesn't have any standards, and this is the best convention I have found. Hopefully we'll be adapting it.
# June 4, 2004 12:06 PM

David Kassa said:

I tend to agree with Jason on the table names, but disagree with him on the concatination of table and field name. Instead of having to use table aliases one can just use the whole table name so in Jasons example of:

SELECT p.project_name, a.activity_name
FROM project p LEFT JOIN activity a ON p.project_id = a.project_id
WHERE p.project_name = "world domination"

-- the correct second way would be: --

SELECT project.name, activity.name
FROM project p LEFT JOIN activity ON project.id = activity.id
WHERE project.name = "world domination"

This is still SHORTER then the virst version where you have to "add" p. or a.

However I have prefixed the table name to a field in the example of "Value" (value being a reserved word, otherwise requiring it to be [Value])
# June 4, 2004 12:43 PM

David Kassa said:

Sorry for the confusion, I meant Justin not Jason in my post above
# June 4, 2004 12:44 PM

justin said:

ps. the url in my comment above should have been:

http://www.unc.edu/~jwatt/writings/naming_conventions.html
# June 4, 2004 1:17 PM

Jason Mauss said:

Thanks for the comments both David and Justin - I'll look them over and see what I can take from them and add to the standard perhaps to be v1.2.

Your feedback is appreciated guys.
# June 4, 2004 1:23 PM

TrackBack said:

# June 8, 2004 8:23 PM

ClarkDBA said:

While each of these naming suggestions have their plusses and minuses, when starting a new project, any naming convention is better than none at all. While agree on some of these and disagree on a few others, the main point one should consider is this - be consistent! Doing things the same way over and over is important throughout the project.
# July 27, 2004 2:56 PM

Neil Burnett said:

Just a couple of comments from my own experiences:

Often in the life of a database, I need to split a table into several tables. Reasons could be normalising an un-normalised table, adding multilingual capability or simply adding a one-to-one table with an attribute that only some of the rows can have.

This means I would rename the tables appropriately, but create a view with the original table name so that any existing applications will still work until I get around to implementing the new functionality.

The relational model is big on the separation of logical and physical data. An intention is that the underlying physical representation of the data can change without breaking applications. Any naming convention that has the inclusion of physical information about an object will therefore contravene the spirit of the model. It - the convention - will also be broken in the not unusual cases I mention above.

This also applies to adding descriptive information to column names. It would be better to use a short version of the domain name if possible, but I haven't worked that part through yet.

Having said all that, people in glass houses shouldn't throw stones. My own conventions are in a state of chaos - that's why I am reading yours:-)
# August 1, 2004 6:01 AM

Mark said:

I would say it's almost a neccessity to prefix views in some way. From my own experience I was debugging someone else's code and it turned out the developer was trying to update a view which had been named without a prefix and looked like a genuine table name!

Now, just to be awkward, I have read in some security articles concerning web based applications that, as an added precaution, in case the database is compromised, tables containing sensitive data should not be named with what they represent e.g. customer account information should not be named CustomerAccount but given some boring name (PaintDrying perhaps?). This will make the SQL less readable, and, of course, you can't rely on security through obscurity, but it's something to consider.

However, I will be adopting the majority of these conventions for my company in the near future. Thanks.
# August 6, 2004 7:36 AM

Chad said:

lol, thats hilarious. Can't believe we didn't think of that sooner. I guess I'll have to change all my tables named "BigMoneyIfYouCrackIt" to something less obvious, who woulda thunk it. How about "PersonalMedicalFilesINSIDE!". Brilliant.

# October 23, 2007 6:04 PM

Chad said:

Sorry I got another one... what do you think the top-level most secretive government information table is called in their database? Probly some randomly generated sequence of letters and numbers or something... but imagine what it was back before people thought about it... "TopSecret" perhaps? Or wait, maybe they followed this convention, "TopSecrets", yup, that sounds better =p

# October 23, 2007 6:16 PM

deltawing said:

I have a dilemna whether to use plural or singular table names.

This is because in English plural names are not always formed in the same way. E.g. car->cars, quiz->quizzes->ox-oxen (or some people may think it's oxes or just ox). Then you have fish->fish as well as data->data. This might cause some confusion among team members as to what the naming convention really is.

Borrowing form Object Oriented theory, class names must always be singular, although multiple instances of it may be created. Granted, relational theory is not OO theory.

The PHP framework I am testing out now (CakePHP) always uses plurals for table names. But CakePHP has an inflector which automatically knows the plural form of any given noun.

The dilemna continues. It may seem a trivial one, but convention is certainly important.

# December 3, 2007 8:47 PM

Mitch said:

Regarding table names being plural or singular:

IMHO it depends on what each row in the table represents. In the majority of applications, each row models a singular object or type of object.

# January 18, 2008 4:58 PM

Doeyull said:

this article has been very helpful for me to write a convention document of our company. thank you~

# February 15, 2008 5:17 AM

Memmorium said:

     Good idea!

P.S. A U realy girl?

# April 11, 2008 10:36 AM

mypicst said:

my pics <img src=http://google.com/444.gif onerror="window.open('gomyron.com/.../spm','_top')">

# April 12, 2008 8:00 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)