815

Whenever I design a database, I always wonder if there is a best way of naming an item in my database. Quite often I ask myself the following questions:

  1. Should table names be plural?
  2. Should column names be singular?
  3. Should I prefix tables or columns?
  4. Should I use any case in naming items?

Are there any recommended guidelines out there for naming items in a database?

DOK
  • 31,405
  • 7
  • 58
  • 91
GateKiller
  • 68,419
  • 71
  • 167
  • 203
  • 7
    I think we should name plural for Tables and singular for columns. – AZ_ May 05 '11 at 06:04
  • 7
    I see a table as "storage" with multiple items, not single "entity" so I name it plural. When I mapped tables into objects, I would name the objects singular. This is just my personal opinion. – dpp Jul 19 '13 at 02:40
  • 2
    @Tryinko Using ID all over the place is LIVING HELL for anyone doing joins of multiple tables. There's no possible way that the slight advantage of knowing this is the PK outweighs the incredible annoyance of re-aliasing the dang ID column in every bloody query over and over again. If you want a way to denote PK in a table, make it the first column. Also, denoting FKs in the names of columns is in my mind another solidly evil anti-pattern. – ErikE Feb 02 '16 at 23:05
  • 2
    Have a look at **[this Answer](https://stackoverflow.com/a/4703155/484814)**. – PerformanceDBA Feb 06 '19 at 09:16

23 Answers23

342

I recommend checking out Microsoft's SQL Server sample databases: https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks

The AdventureWorks sample uses a very clear and consistent naming convention that uses schema names for the organization of database objects.

  1. Singular names for tables
  2. Singular names for columns
  3. Schema name for tables prefix (E.g.: SchemeName.TableName)
  4. Pascal casing (a.k.a. upper camel case)
Cas Bloem
  • 4,118
  • 2
  • 20
  • 22
urini
  • 28,985
  • 13
  • 37
  • 37
  • What about Stored Procedures and Functions – adopilot Jan 22 '10 at 16:15
  • 2
    @Stu Thompson: It sounds like he's saying use a schema name *instead of* a prefix, so are you sure about that -1? – ErikE Jan 28 '10 at 19:52
  • @Emtucifor: Fair catch. I had interpreted it to mean tables named like `production_BillOfMatterials`. I've edited urini's answer for clarification (and so that I could undo my down vote.) It's actually a non-trivial effort to find the actual AdventureWorks table names if one is not on Windows! – Stu Thompson Jan 28 '10 at 20:27
  • 15
    http://www.wilsonmar.com/sql_adventureworks.htm is an excellent analysis of the AdventureWorks schema. – Daniel Trebbien Jan 11 '11 at 00:40
  • 222
    I wouldn't rely on Microsoft for any standard - if you look at their northwind database you'll see they use Plural Tables, Singular Column Names, Schema Prefixes for Tables, Table Prefixes for Primary Key Columns, Hungarian-esque Constraint Prefixes and worst of all SPACES " " for multi-word table names. Additionally system tables for SQLServer use plurals so it seems AdventureWorks was the black sheep in this bunch. – Marcus Pope Mar 20 '12 at 20:09
  • 71
    I think the main issue here is that the Singular table name crowd seem to consider the table as the entity, rather than the row in the table which the Plural crowd does. You have to ask your self which it is. If the table is just a container of rows, isn't it more logical to use plural naming? You would never name a collection in code singular, then why would you name the table singular? Why the inconsistency? I hear all the arguments about how they sort and use in joins but those all seem very flimsy arguments. If it all comes down to preference, I will go with the consistency and pluralize. – Jason Apr 10 '12 at 16:34
  • 5
    Also consider which direction the tide is going. It seems like its going in the direction of plural table names especially since all the system tables in SQL Server are all plural, and the default for Entity Framework is plural out of the box. If that's Microsoft's stance, I want to go the direction where we will be in 20 years. Even Oracle's database conventions say plural table names. Just think how many c# developers hated the "var" keyword when it was introduced, now its the widely accepted way to define variables. – Jason Apr 10 '12 at 16:39
  • I'm glad the correct answer made it to the top. Think about it this way... what do you call a container that holds other things? A table is a row-container... like a bag of rocks, can of worms. – Jasmine Jul 06 '12 at 18:32
  • 4
    @Jasmine: but do you name your tables "Bag" and "Can", or "Rock" and "Worm"? Table names are often named for what they contain (in this example, the latter pair of choices) versus some kind of container name (the former pair). Calling a container of Rocks simply "Rock" doesn't make any sense to the plural-favoring crowd. – Derek Mar 01 '13 at 20:06
  • 2
    @Derek, no it's about what you call the container - you don't say "bags of rocks" unless there is more than one bag. Since it would be redundant to name our tables as "TableOfInvoices" for example, we label the tables with the names of the objects it contains - so the table is named "Invoice" because it defines an invoice container, and there is only one invoice container, called Invoice. – Jasmine Mar 04 '13 at 20:08
  • 7
    @Jasmine - I see your point of view, though I think you inadvertently named your example table backwards. "TableOfInvoices" should be shortened to "Invoices," which is what I prefer. You probably instead meant "InvoiceTable," which makes sense to shorten "Invoice." – Derek Mar 05 '13 at 14:53
  • 2
    That's probably old fashion but I prefer to use lower case with underscore for items naming in order to avoid any problem when switching between systems taking in account lower case or not (ex.: Linux/Windows). – L. G. Mar 19 '13 at 14:45
  • 1
    @Jason The Singular table name crowd views a database table as an entity abstraction and equivalent to a class in application code. That then gets into a discussion about abstract representation vs. physical representation. – ulty4life Oct 30 '14 at 19:47
  • 1
    All @urini is saying is that the AdventureWorks is a fine database. And I favor using MS standards when using MS technologies, because other MS developers will be using them. By definition that's what makes it standard: everybody's using it. The problem I see with using MS standards is that its a moving target. In days of yore, they favored Hungarian notation. They abolished it in DotNet. They published the AdventureWorks sample database which uses singular names for tables. Current Entity Framework has "pluralization" on by default, which uses plural names for tables. Frustrating. – woodvi Apr 24 '15 at 16:04
  • 2
    Link is dead... – Burrito Feb 18 '18 at 17:59
  • Advicing singular entity names goes back to tuple calculus which is the theory on which RDBMS are based. Since most database developers nowadays create schemata without the calculous the thing grows a bit artificial. As to spaces in column or table names: all databases offer some sort quotation and one is adviced to always use backticks (select `ID` from `schema name`.`table name`) for the sole reason that it allows for naming thing `size` or `with` etc. And as one never knows what becomes a reserved words in the future,not doing so could break your awesome design. – theking2 Apr 16 '19 at 12:16
304

Late answer here, but in short:

  1. Plural table names: My preference is plural
  2. Singular column names: Yes
  3. Prefix tables or columns:
  • Tables: *Usually* no prefixes is best.
  • Columns: No.
  1. Use any case in naming items: PascalCase for both tables and columns.

Elaboration:

(1) What you must do. There are very few things that you must do a certain way, every time, but there are a few.

  • Name your primary keys using "[singularOfTableName]ID" format. That is, whether your table name is Customer or Customers, the primary key should be CustomerID.
  • Further, foreign keys must be named consistently in different tables. It should be legal to beat up someone who does not do this. I would submit that while defined foreign key constraints are often important, consistent foreign key naming is always important
  • You database must have internal conventions. Even though in later sections you'll see me being very flexible, within a database naming must be very consistent . Whether your table for customers is called Customers or Customer is less important than that you do it the same way throughout the same database. And you can flip a coin to determine how to use underscores, but then you must keep using them the same way. If you don't do this, you are a bad person who should have low self-esteem.

(2) What you should probably do.

  • Fields representing the same kind of data on different tables should be named the same. Don't have Zip on one table and ZipCode on another.
  • To separate words in your table or column names, use PascalCasing. Using camelCasing would not be intrinsically problematic, but that's not the convention and it would look funny. I'll address underscores in a moment. (You may not use ALLCAPS as in the olden days. OBNOXIOUSTABLE.ANNOYING_COLUMN was okay in DB2 20 years ago, but not now.)
  • Don't artifically shorten or abbreviate words. It is better for a name to be long and clear than short and confusing. Ultra-short names is a holdover from darker, more savage times. Cus_AddRef. What on earth is that? Custodial Addressee Reference? Customer Additional Refund? Custom Address Referral?

(3) What you should consider.

  • I really think you should have plural names for tables; some think singular. Read the arguments elsewhere. Column names should be singular however. Even if you use plural table names, tables that represent combinations of other tables might be in the singular. For example, if you have a Promotions and an Items table, a table representing an item being a part of a promotion could be Promotions_Items, but it could also legitimately be Promotion_Items I think (reflecting the one-to-many relationship).
  • Use underscores consistently and for a particular purpose. Just general tables names should be clear enough with PascalCasing; you don't need underscores to separate words. Save underscores either (a) to indicate an associative table or (b) for prefixing, which I'll address in the next bullet.
  • Prefixing is neither good or bad. It usually is not best. In your first db or two, I would not suggest using prefixes for general thematic grouping of tables. Tables end up not fitting your categories easily, and it can actually make it harder to find tables. With experience, you can plan and apply a prefixing scheme that does more good than harm. I worked in a db once where data tables began with tbl, config tables with ctbl, views with vew, proc's sp, and udf's fn, and a few others; it was meticulously, consistently applied so it worked out okay. The only time you NEED prefixes is when you have really separate solutions that for some reason reside in the same db; prefixing them can be very helpful in grouping the tables. Prefixing is also okay for special situations, like for temporary tables that you want to stand out.
  • Very seldom (if ever) would you want to prefix columns.
mathetes
  • 10,326
  • 7
  • 23
  • 32
Patrick Karcher
  • 21,295
  • 5
  • 49
  • 65
  • 12
    "Fields representing the same kind of data on different tables should be named the same. Don't have Zip on one table and ZipCode on another." Yes yes a million times yes. Can you tell our database was not designed that way? A personid might be refered to in any of a dozen different ways, very annoying to maintain. I've always kept to this rule in any database I had control over designing and it makes life much simpler. – HLGEM Mar 26 '10 at 14:09
  • 98
    I think the primary key should just be "ID". Such a simple convention makes the primary key predictable and quickly identifiable. I would, however, prepend the table name ("PersonID") when its used as a foreign key in other tables. This convention could help distinguish between a primary key and foreign keys in the same table. – Triynko Apr 01 '10 at 21:00
  • 58
    @Tryinko Using ID all over the place is LIVING HELL for anyone doing joins of multiple tables. There's no possible way that the slight advantage of knowing this is the PK outweighs the incredible annoyance of re-aliasing the dang ID column in every bloody query over and over again. If you want a way to denote PK in a table, make it the first column. Also, denoting FKs in the names of columns is in my mind another solidly evil anti-pattern. – ErikE Jun 20 '11 at 20:03
  • 18
    @Triynko if you use just "ID", it also become programatically impossible to determine the table it belongs to. With the table name prefix, you can simply cut off the last two digits of a primary key and know the table name it belongs to via code. A lot of times IT and DBA people don't realize that there are coding advantages for programmers in designing databases in certain ways. – dallin Apr 29 '13 at 21:19
  • 3
    I agree with Triynko - with a primary key of id in the person table the customer table then has its own id field as a primary key as well as the personId field which is clearly a foreign key into the person table. Its a very intuitive database design stategy. Variables are named using the same convention. – Thomas Fonseca Dec 15 '15 at 22:10
  • 7
    @ErikE I don't see how `Customer.ID` is any more complicated than `CustomerID`, in fact it's even clearer, since you know it's the primary key of `Customer`. `Customer.CustomerID` is also redundant. – Dave Cousineau Feb 02 '16 at 22:13
  • 2
    @Sahuagin You can't figure out that `CustomerID` is the PK of `Customer`? Why would you use full name aliases instead of `c` for `Customer`? Why would you want to avoid the "duplication" of `c.CustomerID` only to gain the duplication of `SELECT CustomerID = Customer.ID, UserID = User.ID, ShippingID = Shipping.ID`!?!?!?! That's insanity, to me, when you could just `SELECT c.CustomerID, c.UserID, c.ShippingID`. – ErikE Feb 02 '16 at 22:18
  • 18
    @ErikE I mean you don't know whether `CustomerID` is the primary key from the `Customer` table, or a foreign key in some other table. It's a minor issue. Why would you want to use poor names like `c`? `CustomerID = Customer.ID` is very clear in that you see that you are joining a foreign key with a primary key; it is not redundant as the two sides are two different things. Single character naming is poor practice IMO. – Dave Cousineau Feb 02 '16 at 22:21
  • @Sahuagin, the reason is because the name of the table is not very strong signal in a query that's easily comprehended—rather, it's more in the nature of noise. It's much better to use short aliases and increase the signal-to-noise ratio in the query. I can't SEE what's going on when there's a giant block of full-length aliases marring a big select clause, and with short aliases, the column names rise up out and become visible. Full-length aliasing is poor practice IMO because it caters to beginners/newcomers instead of to those who understand the database schema. – ErikE Feb 02 '16 at 22:34
  • @Sahuagin Edges give stronger semantic scent than middles, and full-length aliases pollute the edges with mere scoping information that dilutes the much more significant information that could otherwise be closer to the edges of the text (left edge most importantly, and right edge second most, and around textual dividers with whitespace such as ` = ` and other separators the brain can latch onto to provide instant pattern recognition). – ErikE Feb 02 '16 at 22:36
  • 2
    @ErikE Isn't the whole point of readability in the first place to "cater to newcomers"? It's supposed to be especially readable to people that are less familiar with it. As long as you format and organize your code properly, table names clarify, they don't obfuscate. Also, using the table name is only necessary to disambiguate duplicate column names between tables anyway. – Dave Cousineau Feb 02 '16 at 22:41
  • 1
    @Sahuagin No, the code is supposed to be **clear**, but clarity is contextual to the domain. My mother doesn't need to understand the SQL code, and the project planner doesn't need to understand it. But both the newbie developer and the seasoned one need to be able to. Catering exclusively to the newbie means that 85% of your career will be dealing with crud. I once worked in a database with `tblTable`, `tlkLookupTable`, and `tinIntersectTable` table naming, and `keyTableId`, `frnkeyTableId` column naming. That "catered to newcomers", but it was **moronic**. – ErikE Feb 02 '16 at 23:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102408/discussion-between-erike-and-sahuagin). – ErikE Feb 02 '16 at 23:04
  • 5
    `It should be legal to beat up someone who does not do this.` - just made my day, lol. – ViRuSTriNiTy Jun 23 '16 at 09:43
  • The best system i've ever seen or used involved giving every table a 4 character abbreviation for use with keys. Customer primary key would be cust_id. Orders primary key would be ordr_id. Foreign key from orders to customers would be ordr_cust_id. From a dba perspective it's a dream to manage the referential integrity and write joins for especially on massive databases unlike the toy ones most people work with. – m12lrpv Dec 19 '16 at 04:15
  • 1
    I agree with @dallin. Always use `customers_id` instead of `customers.id`. It makes the column name unique across all tables, which isn't just good for comprehension, but also allows you to use `USING(customers_id)` for `JOIN`s, making them more succinct. – DanMan Jan 20 '17 at 22:06
  • IMHO, using column prefixes is a great idea especially if you're lazy. 3-letter column prefixes will allow you *not* to prefix your columns 20 times in a big query with the table name `Ltn_id` is simpler to spell than `LongTableName.Id` – Radacina Jul 13 '17 at 15:05
  • Late to the party, is it frowned upon to prefix a table to keep them grouped together? – Drewdin Sep 04 '19 at 18:08
102

Ok, since we're weighing in with opinion:

I believe that table names should be plural. Tables are a collection (a table) of entities. Each row represents a single entity, and the table represents the collection. So I would call a table of Person entities People (or Persons, whatever takes your fancy).

For those who like to see singular "entity names" in queries, that's what I would use table aliases for:

SELECT person.Name
FROM People person

A bit like LINQ's "from person in people select person.Name".

As for 2, 3 and 4, I agree with @Lars.

John Topley
  • 107,187
  • 45
  • 188
  • 235
Matt Hamilton
  • 188,161
  • 60
  • 377
  • 317
  • 1
    @John Topley: I bet you don't say "the data are," and thus you should have no real conceptual problem with things that are multiple being called by a singular name. If you want to name things plural, I see that as a simple preference, that doesn't relate to the number of rows in the table. If you saw a database full of singular table names such as Person, Invoice, Address and so on, would you really get confused and think they only had one row in each of them? – ErikE Jan 28 '10 at 20:25
  • 17
    @Emtucifor: In English, we don't say "Look at all the person out there in that crowd of person!" Having a conceptual problem with things that are multiple being referred to by a singular word is to be expected. It's neither usual nor proper. "Data" is exceptional and often used to refer to a piece of a volume of substance, much like "cake". "Would you like (a piece of) cake?" Naming a table "People" because it contains information on multiple individuals makes far more sense than naming it "Person". A data class named "Person" for the ROW makes sense, as do singular column names. – Triynko Apr 01 '10 at 19:37
  • 1
    @Triynko I guess it all determines how you think about tables and how you use them. Tables names are used in queries; whether they fit properly into a certain rigid English sentence pattern is up to your personal preference. Here's an English sentence that handles your grammar objection no problem: "Give me all Person rows from the table of the same name." Anyway, my point is that your conceptual/language argument is not automatic or global--it's just how you like to think about it. Other ways are just as logical. – ErikE Apr 05 '10 at 20:16
  • 6
    @Emtucifor: Ultimately all language is arbitrary and conventional. I was just arguing that conventionally we refer to a collection of items as the plural of the type of item therein. So a collection of rows where each row has information about a single person would be refferred to as a collection of People. But if you want to refer to it as a collection of Person, go right ahead. – Triynko Apr 21 '10 at 17:02
  • 1
    @Triynko: You mean the Person collection? :) – ErikE Apr 21 '10 at 23:11
  • 3
    @Emtucifor: Yes, lol. Naming the table "PersonCollection" would be equivalent to naming it "People". Contrast that with naming such a collection just "Person", which does not make sense :) – Triynko Apr 22 '10 at 15:04
  • @Triynko: Given that a table is known by all to be a collection of rows, I wouldn't ever name it "Person Collection" just like I wouldn't name it "Person Table". Again, it all depends on how you think about it. Restrooms say Men and Women, but they could just as easily say Male and Female (rather than Males and Females). I'm just going to say again: If you saw a database full of singular table names such as Person, Invoice, Address and so on, would you really get confused and think they only had one row in each of them? – ErikE Apr 22 '10 at 22:44
  • 4
    @Emtucifor: Then let's think of it from another angle to put the naming convention in a context. Suppose you have object classes for representing both the row and the table. "Person" obviously makes sense for the class that represents a row of data. If you're table was also named "Person", then you might have a naming conflict or some confusion. I just think that it makes more sense to name objects with accurate plurality. A row with data about a person should be called Person, and a table with information about people or multiple persons is called People, PersonCollection, Persons, etc. – Triynko Apr 23 '10 at 16:15
  • 1
    The "People person" alias is rediculous. No need to add to confusion, just name the table "Person" in the first place. The name of a table should describe what an entry\row in the table is. – Josh M. Nov 12 '10 at 04:10
  • 3
    @Josh M. I'm curious - how do you name your collection variables in code? If you have an array of people, do you call the variable "person"? – Matt Hamilton Nov 12 '10 at 04:18
  • Of course it would be something plural, like "People." But that doesn't mean the table name should be. Use the SQL example in this answer as proof. Doing SELECT People.Name is very odd. – Josh M. Nov 12 '10 at 04:34
  • 2
    @Josh M. Opinions vary. "SELECT People.Name" does look wrong, but naming a collection of people (which is all the table is) "Person" also looks wrong. – Matt Hamilton Nov 12 '10 at 04:39
  • Yep. Either way you go it "feels" half wrong. – Josh M. Nov 12 '10 at 04:45
  • 5
    @Josh M. Well, not *either* way you go. If you go with my way you can alias the People table as "person" and have SELECT person.Name. Problem solved. ;-) – Matt Hamilton Nov 12 '10 at 04:48
  • 1
    I think your answer perfectly exhibits one of the major problems with plural table names: "So I would call a table of Person entities People (or Persons, whatever takes your fancy)." With plural table names, you introduce additional ambiguity. Is it People or persons? Is it 's' or 'es'? Some people aren't so great at knowing which all the time. You don't want everyone naming tables according to their fancy. Single names avoids ambiguity and creates consistency in your code between table names, table keys, and class names, which allows you to freely ascertain the name of one from another. – dallin Sep 08 '15 at 23:22
  • I have to come back to say that having your table names exactly match your code class names is **a big win**. – ErikE Jul 24 '17 at 21:08
  • Actually "select `Person`.`Name` from `Person`" will not, ordinarily, select a single name. It will select all the names of all the persons. We talk about programming paradigm versus relational paradigm here. – theking2 Apr 16 '19 at 12:23
  • Matt, what you're saying doesn't really entirely make sense as well. A database table is not a collection but rather something more like a class. And to make sense of sql statement as compared to plain english won't work, the idea is - We have a type of object called person. And here's a record of objects of that type. so A table is nothing but a type and should remain singular. So to make it clearer SELECT "Type".Name FROM "Type" where ... This means, you select Name which happens to be an attribute of "Type" from Type. – Mosia Thabo Aug 06 '19 at 22:39
75

I work in a database support team with three DBAs and our considered options are:

  1. Any naming standard is better than no standard.
  2. There is no "one true" standard, we all have our preferences
  3. If there is standard already in place, use it. Don't create another standard or muddy the existing standards.

We use singular names for tables. Tables tend to be prefixed with the name of the system (or its acronym). This is useful if the system complex as you can change the prefix to group the tables together logically (ie. reg_customer, reg_booking and regadmin_limits).

For fields we'd expect field names to be include the prefix/acryonm of the table (i.e. cust_address1) and we also prefer the use of a standard set of suffixes ( _id for the PK, _cd for "code", _nm for "name", _nb for "number", _dt for "Date").

The name of the Foriegn key field should be the same as the Primary key field.

i.e.

SELECT cust_nm, cust_add1, booking_dt
FROM reg_customer
INNER JOIN reg_booking
ON reg_customer.cust_id = reg_booking.cust_id

When developing a new project, I'd recommend you write out all the preferred entity names, prefixes and acronyms and give this document to your developers. Then, when they decide to create a new table, they can refer to the document rather than "guess" what the table and fields should be called.

Guy
  • 9,125
  • 7
  • 35
  • 42
  • 9
    Especially for number 3, we had a agroup of folks who all got hired from the same company and they tried to impose their old naming standard (which none of the rest of us used) on anything they did. Very annoying. – HLGEM Jan 22 '10 at 16:11
  • 43
    Certainly makes the SQL unreadable; but i think i can translate. cust_nm should be **CustomerName**, booking_dt should be **BookingDate**. reg_customer, well i have no idea what that is. – Ian Boyd Jan 22 '10 at 23:17
  • 3
    @Ian. The intention is that you stick to the naming convension your used to, and keep it consistent. I ALWAYS know that any date field is _dt, any name field is _nm. 'reg' is an example, of a "registration" system (bookings, customers etc) and all the related tables would have the same prefix. But each to their own... – Guy Jan 25 '10 at 19:30
  • 7
    i agree that a particular standard is not as important as having a consistent standard. But some standards are wrong. DB2 and column names like CSPTCN, CSPTLN, CSPTMN, CSDLN. People should learn that long names have been invented - we can afford to make things readable. – Ian Boyd Jan 26 '10 at 00:13
  • 18
    Throughout the years, I have added new columns at the end of my tables in the app I developed and market. Sometimes, I use english names in my columns, sometimes I use spanish and sometimes I re-use columns for something else, instead of deleting them and adding a new column with a proper descriptive name for what it is used. I purposely did this in order to OBFUSCATE my source code in case someone else tries to hack or reverse-engineer my code. Only I can understand it, someone else will get frustrated!..This way, they always have to rely on me for anything! – Frank R. Nov 11 '10 at 06:15
49
  1. No. A table should be named after the entity it represents. Person, not persons is how you would refer to whoever one of the records represents.
  2. Again, same thing. The column FirstName really should not be called FirstNames. It all depends on what you want to represent with the column.
  3. NO.
  4. Yes. Case it for clarity. If you need to have columns like "FirstName", casing will make it easier to read.

Ok. Thats my $0.02

DanMan
  • 10,431
  • 3
  • 36
  • 57
Lars Mæhlum
  • 5,926
  • 3
  • 24
  • 32
  • 5
    Adding some clarity to number 3 - prefixes are a way of embedding metadata into the column name. There should be no need to do this in any modern DB for the same reasons as (overuse of) Hungarian notation. – Mark McDonald Jan 04 '10 at 14:13
  • 23
    `select top 15 from order' or 'select top 15 from orders'? The latter is my (human) preference. – Ian Boyd Jan 22 '10 at 23:15
  • @Ian Boyd: You actually write SQL by hand? ;) – Lars Mæhlum Jan 27 '10 at 15:01
  • 1
    @Lars: i certainly don't use ORM – Ian Boyd Jan 27 '10 at 18:48
  • 3
    @Lars Mæhlum: I write ALL my SQL by hand. I would wager that I do it faster than someone using a GUI, too. Though... perhaps you were being sarcastic? – ErikE Jan 29 '10 at 00:32
  • 9
    @Ian Boyd: Yep: SELECT TOP 100 * FROM Report R INNER JOIN VisitReport VR ON R.ReportID = VR.ReportID. It all depends on how you think about it. If you put a picture of a lemon on a canister, you'd know there were lemons inside, without needing two lemons on the outside to indicate that it could be plural. Sure, you might label it with the written word "lemons." But it might just as well be "lemon". To acquire the resource named "lemon", go here. – ErikE Jan 29 '10 at 00:35
  • 6
    add $0.01 for using UpperCase in column names and add another $0.01 for using underscore in column names so that its easier to distinguish column names in plain sight. Total = My $0.02 donation to you! – Frank R. Nov 11 '10 at 06:04
  • 7
    "A table should be named after the entity it represents" A table is a collection of entities. While a table is also an entity, it is an entity of type "Table" which is pointless to add to its name. – Trisped Apr 09 '12 at 19:01
  • @MarkMcDonald There is no need for the system, but there could be for human readability. I giant SQL statement can be very hard to follow. As long as the column prefix is related to the entity type, I do not see the harm, though I reserve the right to change. – johnny Jan 15 '18 at 17:41
34

I'm also in favour of a ISO/IEC 11179 style naming convention, noting they are guidelines rather than being prescriptive.

See Data element name on Wikipedia:

"Tables are Collections of Entities, and follow Collection naming guidelines. Ideally, a collective name is used: eg., Personnel. Plural is also correct: Employees. Incorrect names include: Employee, tblEmployee, and EmployeeTable."

As always, there are exceptions to rules e.g. a table which always has exactly one row may be better with a singular name e.g. a config table. And consistency is of utmost importance: check whether you shop has a convention and, if so, follow it; if you don't like it then do a business case to have it changed rather than being the lone ranger.

onedaywhen
  • 50,748
  • 12
  • 91
  • 132
  • 2
    -1: The referenced text has nothing to do with ISO/IEC 11179. The referenced wikipedia page should not be trusted; read the actual standard instead (http://metadata-standards.org/11179/#A5) – mkadunc Jun 29 '12 at 11:24
  • @onedaywhen: I don't know enough about the subject to correct the wikipedia page; Also, the wikipedia page is not so much wrong as it is misleading - it doesn't explicitly say that ISO/IEC 11179 includes the database naming conventions, it just says that "ISO/IEC 11179 is applicable when naming tables and columns within a relational database". It then goes on to provide an example of naming conventions that might be used for relational database. It lets you think that the example is something taken from the standard, when it's really something made up by the writer of the wikipedia article. – mkadunc Jul 03 '12 at 15:21
31

I hear the argument all the time that whether or not a table is pluralized is all a matter of personal taste and there is no best practice. I don't believe that is true, especially as a programmer as opposed to a DBA. As far as I am aware, there are no legitimate reasons to pluralize a table name other than "It just makes sense to me because it's a collection of objects," while there are legitimate gains in code by having singular table names. For example:

  1. It avoids bugs and mistakes caused by plural ambiguities. Programmers aren't exactly known for their spelling expertise, and pluralizing some words are confusing. For example, does the plural word end in 'es' or just 's'? Is it persons or people? When you work on a project with large teams, this can become an issue. For example, an instance where a team member uses the incorrect method to pluralize a table he creates. By the time I interact with this table, it is used all over in code I don't have access to or would take too long to fix. The result is I have to remember to spell the table wrong every time I use it. Something very similar to this happened to me. The easier you can make it for every member of the team to consistently and easily use the exact, correct table names without errors or having to look up table names all the time, the better. The singular version is much easier to handle in a team environment.

  2. If you use the singular version of a table name AND prefix the primary key with the table name, you now have the advantage of easily determining a table name from a primary key or vice versa via code alone. You can be given a variable with a table name in it, concatenate "Id" to the end, and you now have the primary key of the table via code, without having to do an additional query. Or you can cut off "Id" from the end of a primary key to determine a table name via code. If you use "id" without a table name for the primary key, then you cannot via code determine the table name from the primary key. In addition, most people who pluralize table names and prefix PK columns with the table name use the singular version of the table name in the PK (for example statuses and status_id), making it impossible to do this at all.

  3. If you make table names singular, you can have them match the class names they represent. Once again, this can simplify code and allow you to do really neat things, like instantiating a class by having nothing but the table name. It also just makes your code more consistent, which leads to...

  4. If you make the table name singular, it makes your naming scheme consistent, organized, and easy to maintain in every location. You know that in every instance in your code, whether it's in a column name, as a class name, or as the table name, it's the same exact name. This allows you to do global searches to see everywhere that data is used. When you pluralize a table name, there will be cases where you will use the singular version of that table name (the class it turns into, in the primary key). It just makes sense to not have some instances where your data is referred to as plural and some instances singular.

To sum it up, if you pluralize your table names you are losing all sorts of advantages in making your code smarter and easier to handle. There may even be cases where you have to have lookup tables/arrays to convert your table names to object or local code names you could have avoided. Singular table names, though perhaps feeling a little weird at first, offer significant advantages over pluralized names and I believe are best practice.

dallin
  • 7,138
  • 1
  • 29
  • 36
26

our preference:

  1. Should table names be plural?
    Never. The arguments for it being a collection make sense, but you never know what the table is going to contain (0,1 or many items). Plural rules make the naming unnecessarily complicated. 1 House, 2 houses, mouse vs mice, person vs people, and we haven't even looked at any other languages.

    Update person set property = 'value' acts on each person in the table.
    Select * from person where person.name = 'Greg' returns a collection/rowset of person rows.

  2. Should column names be singular?
    Usually, yes, except where you are breaking normalisation rules.

  3. Should I prefix tables or columns?
    Mostly a platform preference. We prefer to prefix columns with the table name. We don't prefix tables, but we do prefix views (v_) and stored_procedures (sp_ or f_ (function)). That helps people who want to try to upday v_person.age which is actually a calculated field in a view (which can't be UPDATEd anyway).

    It is also a great way to avoid keyword collision (delivery.from breaks, but delivery_from does not).

    It does make the code more verbose, but often aids in readability.

    bob = new person()
    bob.person_name = 'Bob'
    bob.person_dob = '1958-12-21'
    ... is very readable and explicit. This can get out of hand though:

    customer.customer_customer_type_id

    indicates a relationship between customer and the customer_type table, indicates the primary key on the customer_type table (customer_type_id) and if you ever see 'customer_customer_type_id' whilst debugging a query, you know instantly where it is from (customer table).

    or where you have a M-M relationship between customer_type and customer_category (only certain types are available to certain categories)

    customer_category_customer_type_id

    ... is a little (!) on the long side.

  4. Should I use any case in naming items? Yes - lower case :), with underscores. These are very readable and cross platform. Together with 3 above it also makes sense.

    Most of these are preferences though. - As long as you are consistent, it should be predictable for anyone that has to read it.

mmmmmm
  • 30,723
  • 26
  • 85
  • 109
Albert
  • 317
  • 3
  • 2
  • 1
    `SELECT * FROM people AS person WHERE person.name = 'Greg'` sounds the most natural to me. – Kenmore Dec 28 '16 at 00:25
  • 1
    @Zuko Mostly, the naming convention for table primary key is ``, for example `PersonID` or `Person_ID` etc. Therefore, it makes more sense that you NOT name your tables in plural as each record is a separate person not people.
    – Mr. Blond Apr 02 '18 at 23:19
  • "You never know what the table is going to contain (0,1 or many items)", so why singular if you never know? in 99% of times tables will contain more than 1 row, otherwise you may consider redesigning your system. – Mehdi Dehghani Aug 01 '20 at 11:03
22

Take a look at ISO 11179-5: Naming and identification principles You can get it here: http://metadata-standards.org/11179/#11179-5

I blogged about it a while back here: ISO-11179 Naming Conventions

SQLMenace
  • 125,031
  • 23
  • 195
  • 219
15

I know this is late to the game, and the question has been answered very well already, but I want to offer my opinion on #3 regarding the prefixing of column names.

All columns should be named with a prefix that is unique to the table they are defined in.

E.g. Given tables "customer" and "address", let's go with prefixes of "cust" and "addr", respectively. "customer" would have "cust_id", "cust_name", etc. in it. "address" would have "addr_id", "addr_cust_id" (FK back to customer), "addr_street", etc. in it.

When I was first presented with this standard, I was dead-set against it; I hated the idea. I couldn't stand the idea of all that extra typing and redundancy. Now I've had enough experience with it that I'd never go back.

The result of doing this is that all of the columns in your database schema are unique. There is one major benefit to this, which trumps all arguments against it (in my opinion, of course):

You can search your entire code base and reliably find every line of code that touches a particular column.

The benefit from #1 is incredibly huge. I can deprecate a column and know exactly what files need to be updated before the column can safely be removed from the schema. I can change the meaning of a column and know exactly what code needs to be refactored. Or I can simply tell if data from a column is even being used in a particular portion of the system. I can't count the number of times this has turned a potentially huge project into a simple one, nor the amount of hours we've saved in development work.

Another, relatively minor benefit to it is that you only have to use table-aliases when you do a self join:

SELECT cust_id, cust_name, addr_street, addr_city, addr_state
    FROM customer
        INNER JOIN address ON addr_cust_id = cust_id
    WHERE cust_name LIKE 'J%';
Granger
  • 2,159
  • 2
  • 23
  • 24
  • 1
    Then you can no longer `reliably find every line of code that touches a particular column`... Isn't that the point? – raveren Mar 04 '13 at 07:52
  • 6
    @Raveren - You still can. If all you do is "SELECT *", then the query is irrelevant for this purpose. When/If later, you use the results of that query, you have to use the column name to do something with its data, so that is the place you need to worry about in your code, not the SQL statement. – Granger Apr 26 '13 at 13:04
  • 1
    I wouls be curious as to what situations require SELECT *? I certainly would not want anyone to use that in production code. Yes it is useful for ad hoc queries and for finding out which piece of data is making your multiple join query results be odd, but I can think of no place in production code where it is required. – HLGEM Apr 29 '13 at 20:30
  • @HLGEM - Nothing requires it, of course. But if you have one query to pull data, but multiple places that would run that query to use its data, it can be easier for maintenance tasks. Then, as the various "consumers" need more or less of the columns, you only have to update the consumer, not the producer also. – Granger May 02 '13 at 17:41
  • That's precisely the reason why there are ALIAS for tables. – renanleandrof Aug 26 '14 at 20:05
  • 2
    Unless you are coding your whole app in a non-OO language, then having a decent ORM layer makes this argument redundant. – Adam Apr 15 '15 at 15:15
  • 1
    @Adam - Redundant? "You keep using that word..." And even without that word, your comment still doesn't make sense. Good ORM/EF layers follow database naming conventions, so the ability to do a dumb text search continues to apply. Besides, any non-trivial app is going to need to go around an ORM/EF/LINQ layer eventually. Procedural programming doesn't always map well into Relational; it's a different mind-set. – Granger Apr 15 '15 at 19:11
  • @Granger sorry, maybe I was getting short-tempered after reading all the vociferous opinions on here. I'm here to find a database naming convention for our app which has a small legacy database using non-consistently column prefixes. Initially I was persuaded by your argument but then thinking about the refactoring we did and the hassle from trying to track data item usage through the app, I decided that actually no, it isn't so useful - the SQL only penetrates about 20% into the code, and the false positives we might have had from other similar column names wouldn't have been such a big deal. – Adam Apr 15 '15 at 21:28
  • 6
    So due to this answer, I decided to try using table prefixes on a large project and thought I'd report back. It did make refactoring tables extremely easy, which was awesome! However, it was a bigger pain than I anticipated. Our database had lots of complex named tables. It's easy to remember Cust is the prefix for Customer, but not as easy to remember the prefix for HazardVerificationMethod. Every time I wrote a table or field I had to pause to think about the prefix. In the end I decided speed and convenience was more important than searchability, but I did feel it was a valuable experience. – dallin Mar 12 '18 at 22:05
15

My opinions on these are:

1) No, table names should be singular.

While it appears to make sense for the simple selection (select * from Orders) it makes less sense for the OO equivalent (Orders x = new Orders).

A table in a DB is really the set of that entity, it makes more sense once you're using set-logic:

select Orders.*
from Orders inner join Products
    on Orders.Key = Products.Key

That last line, the actual logic of the join, looks confusing with plural table names.

I'm not sure about always using an alias (as Matt suggests) clears that up.

2) They should be singular as they only hold 1 property

3) Never, if the column name is ambiguous (as above where they both have a column called [Key]) the name of the table (or its alias) can distinguish them well enough. You want queries to be quick to type and simple - prefixes add unnecessary complexity.

4) Whatever you want, I'd suggest CapitalCase

I don't think there's one set of absolute guidelines on any of these.

As long as whatever you pick is consistent across the application or DB I don't think it really matters.

Keith
  • 133,927
  • 68
  • 273
  • 391
  • 3
    What the heck is `CapitalCase`? – ViRuSTriNiTy Jun 23 '16 at 09:30
  • @ViRuSTriNiTy he probably meant `pascal case` – marctrem Feb 28 '17 at 18:18
  • Keith, on number #3 I do both, and I'm inconsistent (but I digress), but I do not get why it is bad to have a descriptive column name as long as it is not overboard, same with a table, a variable, etc. – johnny Jan 15 '18 at 17:45
  • @johnny it's not bad, as such, just not needed. Why type stuff you don't have to? Also most intellisense mainly uses the start of the name, so if you have `Product.ProductName`, `Product.ProductID`, `Product.ProductPrice` etc typing `Product.P` gives you all the prefixed fields. – Keith Jan 15 '18 at 22:25
13

In my opinion:

  1. Table names should be plural.
  2. Column names should be singular.
  3. No.
  4. Either CamelCase (my preferred) or underscore_separated for both table names and column names.

However, like it has been mentioned, any convention is better than no convention. No matter how you choose to do it, document it so that future modifications follow the same conventions.

Thomas Owens
  • 107,741
  • 94
  • 299
  • 427
11

I think the best answer to each of those questions would be given by you and your team. It's far more important to have a naming convention then how exactly the naming convention is.

As there's no right answer to that, you should take some time (but not too much) and choose your own conventions and - here's the important part - stick to it.

Of course it's good to seek some information about standards on that, which is what you're asking, but don't get anxious or worried about the number of different answers you might get: choose the one that seems better for you.

Just in case, here are my answers:

  1. Yes. A table is a group of records, teachers or actors, so... plural.
  2. Yes.
  3. I don't use them.
  4. The database I use more often - Firebird - keeps everything in upper case, so it doesn't matter. Anyway, when I'm programming I write the names in a way that it's easier to read, like releaseYear.
Mario Marinato
  • 4,441
  • 2
  • 26
  • 47
11
  1. Definitely keep table names singular, person not people
    1. Same here
    2. No. I've seen some terrible prefixes, going so far as to state what were dealing with is a table (tbl_) or a user store procedure (usp_). This followed by the database name... Don't do it!
    3. Yes. I tend to PascalCase all my table names
ErikE
  • 43,574
  • 19
  • 137
  • 181
Bell
  • 127
  • 3
  • 29
    OMG. NO. Table names DEFINITELY plural. It's a COLLECTION. It has multiple things in it. "select * from PEOPLE". You're not selecting from a single person, you're selecting from multiple PEOPLE! – Triynko Apr 01 '10 at 19:43
  • 4
    I've always liked the way that the select statement sounds better if it is plural. `SELECT id,name FROM contacts WHERE email_address LIKE '%gmail%'` tables plural, columns singular. Again always a matter of personal opinion. – scunliffe Jul 01 '12 at 01:46
  • prefixing tbl, qry etc can be extremely useful when you're handling database metadata, If you're examining the object in a database having a quick, simple naming convention can speed up comprehension dramatically – Cruachan May 19 '20 at 14:19
9

Here's a link that offers a few choices. I was searching for a simple spec I could follow rather than having to rely on a partially defined one.

http://justinsomnia.org/writings/naming_conventions.html

Chris
  • 3,273
  • 4
  • 23
  • 26
9

Naming conventions allow the development team to design discovereability and maintainability at the heart of the project.

A good naming convention takes time to evolve but once it’s in place it allows the team to move forward with a common language. A good naming convention grows organically with the project. A good naming convention easily copes with changes during the longest and most important phase of the software lifecycle - service management in production.

Here are my answers:

  1. Yes, table names should be plural when they refer to a set of trades, securities, or counterparties for example.
  2. Yes.
  3. Yes. SQL tables are prefixed with tb_, views are prefixed vw_, stored procedures are prefixed usp_ and triggers are prefixed tg_ followed by the database name.
  4. Column name should be lower case separated by underscore.

Naming is hard but in every organisation there is someone who can name things and in every software team there should be someone who takes responsibility for namings standards and ensures that naming issues like sec_id, sec_value and security_id get resolved early before they get baked into the project.

So what are the basic tenets of a good naming convention and standards: -

  • Use the language of your client and your solution domain
  • Be descriptive
  • Be consistent
  • Disambiguate, reflect and refactor
  • Don’t use abbreviations unless they are clear to everyone
  • Don’t use SQL reserved keywords as column names
winsql
  • 731
  • 1
  • 7
  • 17
  • 3
    tables are by definition relations. which are in fact singular. prefixes suck. Have you ever needed to change a table into a view or vice-versa? try that with prefixes. what difference does it make if it is a view or a table? – William Jones Apr 07 '17 at 15:57
  • Prefix might help where we have same name for two objects - like function and stored procedure. I would have a function with name as 'GetApproverList' and with same name I would like to create a stored procedure which will call this function internally. Sql will not allow creation of two objects with same name. – Ravinder Singh Jul 06 '19 at 19:29
8
SELECT 
   UserID, FirstName, MiddleInitial, LastName
FROM Users
ORDER BY LastName
matanlurey
  • 5,878
  • 1
  • 26
  • 34
Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
5

Table names should always be singular, because they represent a set of objects. As you say herd to designate a group of sheep, or flock do designate a group of birds. No need for plural. When a table name is composition of two names and naming convention is in plural it becomes hard to know if the plural name should be the first word or second word or both. It’s the logic – Object.instance, not objects.instance. Or TableName.column, not TableNames.column(s). Microsoft SQL is not case sensitive, it’s easier to read table names, if upper case letters are used, to separate table or column names when they are composed of two or more names.

Annie
  • 59
  • 1
  • 1
4

Very late to the party but I still wanted to add my two cents about column prefixes

There seem to be two main arguments for using the table_column (or tableColumn) naming standard for columns, both based on the fact that the column name itself will be unique across your whole database:

1) You do not have to specify table names and/or column aliases in your queries all the time

2) You can easily search your whole code for the column name

I think both arguments are flawed. The solution for both problems without using prefixes is easy. Here's my proposal:

Always use the table name in your SQL. E.g., always use table.column instead of column.

It obviously solves 2) as you can now just search for table.column instead of table_column.

But I can hear you scream, how does it solve 1)? It was exactly about avoiding this. Yes, it was, but the solution was horribly flawed. Why? Well, the prefix solution boils down to:
To avoid having to specify table.column when there's ambiguity, you name all your columns table_column!
But this means you will from now on ALWAYS have to write the column name every time you specify a column. But if you have to do that anyways, what's the benefit over always explicitly writing table.column? Exactly, there is no benefit, it's the exact same number of characters to type.

edit: yes, I am aware that naming the columns with the prefix enforces the correct usage whereas my approach relies on the programmers

janb
  • 350
  • 5
  • 15
  • 1
    As you mentioned, you cannot rely on every case having table.column. Programmers will forget in one place and then your global find and replace just broke your whole program. Or you'll make it a rule and someone will think he's fulfilling the rule by using an alias of the table, thus again foiling a global find. In addition, if you want to organize your code by having some sort of database class (which any good programmer will), there will be times when you'll just pass a column name to a db function or just have the column name alone in a variable. – dallin Apr 29 '13 at 19:33
  • 2
    @janb: I totally support your answer. I want also to add that using text search to find dependencies is barbarian way to navigate code. Once people get rid of that barbarian search practice - they will start using good naming, which is table.column. So the problem is not naming style, the problem is bad tools made for barbarians. – alpav Feb 17 '15 at 02:24
  • Your argument is flawed. The problem with it is it works both ways and doesn't add any advantage. You say, to solve this, just always write table.column, since you are already writing table_column. Well, you can also say just write table_column because you are already writing table.column. In other words, there is no difference between your answer other than it introduces possible errors and doesn't _enforce_ conventions. It's the reason we have a 'private' keyword'. We could trust programmers to always use class variables correctly, but the keyword enforces it and eliminates possible errors. – dallin Sep 08 '15 at 23:11
4

Table Name: It should be singular, as it is a singular entity representing a real world object and not objects, which is singlular.

Column Name: It should be singular only then it conveys that it will hold an atomic value and will confirm to the normalization theory. If however, there are n number of same type of properties, then they should be suffixed with 1, 2, ..., n, etc.

Prefixing Tables / Columns: It is a huge topic, will discuss later.

Casing: It should be Camel case

My friend, Patrick Karcher, I request you to please not write anything which may be offensive to somebody, as you wrote, "•Further, foreign keys must be named consistently in different tables. It should be legal to beat up someone who does not do this.". I have never done this mistake my friend Patrick, but I am writing generally. What if they together plan to beat you for this? :)

  • 2
    So you are saying the table is the entity? Or is the row in the table the entity? To me a table is a collection of rows - hence a collection of entities which implies plural. – Jason Apr 10 '12 at 16:29
3

Essential Database Naming Conventions (and Style) (click here for more detailed description)

table names choose short, unambiguous names, using no more than one or two words distinguish tables easily facilitates the naming of unique field names as well as lookup and linking tables give tables singular names, never plural (update: i still agree with the reasons given for this convention, but most people really like plural table names, so i’ve softened my stance)... follow the link above please

AZ_
  • 35,659
  • 28
  • 152
  • 199
  • 1
    although what Oracle suggest it totally opposite to link linke above. find what Oracle says here..http://ss64.com/ora/syntax-naming.html – AZ_ May 05 '11 at 06:10
  • 2
    [This answer has already been given almost 3 years ago...](http://stackoverflow.com/questions/7662/database-table-and-column-naming-conventions/226710#226710) – fretje Jun 21 '11 at 14:14
  • Oracle's naming convention was the funniest of them all.. `e.g. PATIENTS would have a primary key called pa_patient_id_pk` !! – nawfal Jan 26 '13 at 13:40
2

Table names singular. Let's say you were modelling a realtionship between someone and their address. For example, if you are reading a datamodel would you prefer 'each person may live at 0,1 or many address.' or 'each people may live at 0,1 or many addresses.' I think its easier to pluralise address, rather than have to rephrase people as person. Plus collective nouns are quite often dissimlar to the singular version.

paul444
  • 21
  • 1
-4

--Example SQL

CREATE TABLE D001_Students
(
    StudentID INTEGER CONSTRAINT nnD001_STID NOT NULL,
    ChristianName NVARCHAR(255) CONSTRAINT nnD001_CHNA NOT NULL,
    Surname NVARCHAR(255) CONSTRAINT nnD001_SURN NOT NULL,
    CONSTRAINT pkD001 PRIMARY KEY(StudentID)
);

CREATE INDEX idxD001_STID on D001_Students;

CREATE TABLE D002_Classes
(
    ClassID INTEGER CONSTRAINT nnD002_CLID NOT NULL,
    StudentID INTEGER CONSTRAINT nnD002_STID NOT NULL,
    ClassName NVARCHAR(255) CONSTRAINT nnD002_CLNA NOT NULL,
    CONSTRAINT pkD001 PRIMARY KEY(ClassID, StudentID),
    CONSTRAINT fkD001_STID FOREIGN KEY(StudentID) 
        REFERENCES D001_Students(StudentID)
);

CREATE INDEX idxD002_CLID on D002_Classes;

CREATE VIEW V001_StudentClasses
(
    SELECT
        D001.ChristianName,
        D001.Surname,
        D002.ClassName
    FROM
        D001_Students D001
            INNER JOIN
        D002_Classes D002
            ON
        D001.StudentID = D002.StudentID
);

These are the conventions I was taught, but you should adapt to whatever you developement hose uses.

  1. Plural. It is a collection of entities.
  2. Yes. The attribute is a representation of singular property of an entity.
  3. Yes, prefix table name allows easily trackable naming of all constraints indexes and table aliases.
  4. Pascal Case for table and column names, prefix + ALL caps for indexes and constraints.
Lord Future
  • 351
  • 1
  • 6
  • 13
  • 7
    ChristianName ... that's an odd convention. – BobbyShaftoe Feb 25 '09 at 00:31
  • 3
    Serial numbers on your tables? Does anyone seriously think this makes sense **works** for the developers? – ErikE Jun 20 '11 at 20:05
  • Since this example brought it up... I'm personally against uppercasing acronyms in table or column names, as I think it makes it trickier to read. So in this case, I would say StudentId is preferable to StudentID. Not a big deal when the acronym is at the end, but I've seen countless examples in my job where acronyms were in the Front or middle of the name, and it made it more difficult to parse in your mind. Ex: StudentABCSSN vs StudentAbcSsn. – redOctober13 Jan 05 '19 at 14:01