SQL Naming Conventions: snake_case Through the Years

There's no official SQL naming standard, but the safest default is lowercase snake_case for tables and columns (order_items, created_at), written without quotes. It's the one style that behaves the same way in PostgreSQL, MySQL, SQL Server, Oracle and SQLite, because it survives the different ways those databases fold, compare and quote identifiers.
Almost everything else in SQL naming, from singular or plural tables to id versus order_id, is a team decision. So this post separates the two: first what the databases actually do with your names, then the conventions, then the debates that have no single right answer.
What the SQL standard says, and what databases actually do
In standard SQL, unquoted identifiers are case-insensitive and are folded to uppercase, while identifiers in double quotes keep their exact case. Real databases follow that only loosely:
| Database | Unquoted names | Quoting |
|---|---|---|
| SQL standard | Folded to uppercase | "double quotes", case-sensitive |
| PostgreSQL | Folded to lowercase, which its docs note is incompatible with the standard | "double quotes", case-sensitive |
| Oracle | Interpreted as uppercase | "double quotes", case-sensitive |
| MySQL | Columns are case-insensitive everywhere; database and table names follow the operating system unless lower_case_table_names says otherwise | `backticks`, or double quotes in ANSI_QUOTES mode |
| SQL Server | Depends on the database's collation: a case-sensitive collation allows Orders and orders as two tables, a case-insensitive one doesn't | [brackets], or double quotes with QUOTED_IDENTIFIER on |
| SQLite | Case-insensitive, even inside double quotes | "double quotes"; also accepts brackets and backticks for compatibility |
MySQL deserves a closer look, because its rule comes from the file system. Databases are directories and tables are files, so table names are case-sensitive on most Unix systems and not on Windows. The lower_case_table_names setting defaults to 0 on Unix (stored as written, compared case-sensitively), 1 on Windows (stored in lowercase) and 2 on macOS (stored as written, compared in lowercase), and it can only be set when the server is initialized. MySQL's own manual recommends always creating and referring to databases and tables in lowercase, for portability. The identifier case sensitivity page has the details.
The mixed-case trap
The classic problem starts when a GUI tool or an ORM creates a table with quoted, mixed-case names. In PostgreSQL:
CREATE TABLE "UserAccounts" ("userId" integer, "displayName" text);
SELECT userId FROM UserAccounts;
-- fails: unquoted names are folded, so PostgreSQL looks for
-- a table called useraccounts with a column called userid
SELECT "userId" FROM "UserAccounts";
-- works, but every query now needs quotes, foreverOracle has the same problem in the opposite direction: the unquoted query looks for USERACCOUNTS. Now compare the snake_case version:
CREATE TABLE user_accounts (user_id integer, display_name text);
SELECT user_id, display_name FROM user_accounts;No quotes needed in any of the five databases. Keep your queries in lowercase too, and the same SQL also works on MySQL running on Linux, where User_Accounts and user_accounts would be different tables. PostgreSQL's docs put the rule for portable code simply: either always quote a name or never quote it.
Why snake_case stuck
No major database requires snake_case. It won by being the path of least resistance. Every rule in the table above, from the standard's uppercase folding to PostgreSQL's lowercase folding, MySQL's file-based table names and SQL Server's collations, treats an unquoted lowercase name predictably as long as you write it the same way each time. camelCase is less forgiving. In PostgreSQL and Oracle it only keeps its capitals if you quote it, and then the quotes are part of the name for good; in MySQL on Linux it keeps them unquoted, and every query has to match them exactly.
Length limits pushed in the same direction. Until Oracle Database 12c Release 2, most Oracle object names were capped at 30 bytes (the limit is now 128), which rewarded short, plain names over anything decorative. Django's documentation still mentions shortening and uppercasing table names to fit Oracle's 30-character limit.
SQL naming conventions worth adopting
- Lowercase snake_case for tables, columns, indexes and constraints. Simon Holywell's SQL Style Guide (sqlstyle.guide) puts it simply: use underscores where you'd naturally put a space, and avoid camelCase because it's hard to scan.
- No type prefixes. Skip
tbl_ordersandsp_get_orders. On SQL Server,sp_is worse than redundant: Microsoft's docs say the prefix designates system procedures and warn that using it can break your code if a system procedure with the same name exists. - No reserved words.
user,orderandgroupare reserved in PostgreSQL, so a table calledorderneeds quotes in every query. Plural names (users,orders) or more specific ones (customer_groups) sidestep the problem. - Reasonable length. PostgreSQL truncates identifiers longer than 63 bytes by default, so two long names that differ only at the end can collide. sqlstyle.guide suggests a 30-byte maximum.
- Consistent suffixes.
_idfor keys,_atfor timestamps (created_at),_countor_totalfor numbers. Readers learn the pattern once.
The debates with no single right answer
Singular or plural table names?
Even the big frameworks disagree. Rails pluralizes: a BookClub model maps to a book_clubs table. Django joins the app name and the lowercased model name, so Book in an app called bookstore becomes bookstore_book. sqlstyle.guide prefers a collective noun such as staff, and a plural if there isn't one.
Our take: if an ORM owns the schema, accept its default rather than fighting it table by table. If you're writing SQL by hand, plural reads naturally in FROM orders and dodges reserved words like user and order.
id or order_id for primary keys?
Rails uses a column called id as the primary key and names foreign keys after the singular table: order_id, line_item_id. sqlstyle.guide argues the other way, against a bare id. The trade-off is real. id is short, and Rails and Django both create it by default; order_id on both sides of a relationship makes joins self-explanatory, and in databases that support it lets you write JOIN line_items USING (order_id). Pick one and apply it to every table.
Uppercase or lowercase keywords?
SQL keywords are case-insensitive, so this is purely style. PostgreSQL's docs mention the common convention of uppercase keywords with lowercase names (UPDATE my_table SET a = 5), and sqlstyle.guide requires it. We like uppercase keywords when SQL lives inside application code, because they stand out from the identifiers, but a formatter that does it for you matters more than the choice.
Crossing into application code
Your columns are snake_case, but your JavaScript or C# probably isn't. Convert in one place, usually the ORM's mapping or the API serializer, rather than letting created_at and createdAt both spread through the code. Converting camelCase JSON to snake_case walks through that boundary, and our case converter handles one-off renames such as displayName to display_name. For the conventions in each programming language, see our developer case cheat sheet.
A starter convention to paste into your README
- Tables: plural, lowercase snake_case (
order_items). - Columns: singular snake_case; foreign keys as
singular_table_id(order_id). - Timestamps:
created_at,updated_at. - Indexes and constraints:
idx_orders_customer_id,fk_orders_customer_id. - Never quoted, never reserved words, always lowercase in queries.


