SQL Naming Conventions (2024 Tutorial & Examples) (2024)

SQL tutorial

Learn more about SQL, a standard language for interacting with databases and storing, manipulating, and retrieving data from databases.

Go hands-on with SQL in our free interactive SQL tutorial.

With regards to writing good SQL code, there are a number of SQL naming conventions as well as best practices which should be followed.

Use all lowercase for column and table names and to separate words with an underscore (“_”). For example, start_date and end_date as column names as opposed to StartingDate and EndingDate, and employees as a table name as opposed to Employees. This works together with the good SQL style convention of capitalizing statements names, clauses, and other keywords for better code readability: SELECT start_date, end_date FROM campaign;

For all SQL code and data, using table, column, variable names, or aliases which conflict with SQL keywords and reserved words should be avoided. Tables and columns should be given clear, easily understandable and uniquely identifying names. Abbreviations should not be used unless absolutely necessary as required by the maximum length enforced for column and table names – in which case it is likely that a different, more succinct name should be considered.

While some older style guides suggest it, the general consensus amongst more modern style guides is to avoid table and column names with prefixes or suffixes denoting the data or entity type or are a short abbreviation. For example, a table name of employees is preferable to tbl_employees, and a column name like customer_account_tx is ambiguous, as it is unclear whether tx is an abbreviation for “transaction” or designating that this column is a text field.

While not a hard-and-fast rule, many style guides suggest only using singular nouns for table names for clarity; e.g. customer as opposed to customers.

There are also a number of conventions which are enforced by the SQL engine. Though these vary somewhat between SQL “flavors”, SQL columns and table names should begin with a letter, not end in an underscore, and should contain only alphanumeric characters. Column and table names should not contain spaces. For some varieties of SQL, these rules must be followed explicitly or code will confuse the SQL interpreter and not execute.

Learn SQL Today

Get hands-on experience writing code with interactive tutorials in our free online learning platform.

  • Free and fun
  • Designed for beginners
  • No downloads or setup required
SQL Naming Conventions (2024 Tutorial & Examples) (2024)

FAQs

What is the proper naming convention in SQL? ›

Naming conventions
  1. Ensure the name is unique and does not exist as a reserved keyword.
  2. Keep the length to a maximum of 30 bytes—in practice this is 30 characters unless you are using a multi-byte character set.
  3. Names must begin with a letter and may not end with an underscore.

What is the best practice naming foreign key? ›

What are some best practices for naming primary keys and foreign keys?
  • Use consistent and descriptive names. ...
  • Follow a naming convention. ...
  • Use singular and plural names appropriately. ...
  • Use prefixes or suffixes for foreign keys. ...
  • Avoid using reserved words or symbols. ...
  • Test and validate your names. ...
  • Here's what else to consider.
Mar 12, 2023

What are the rules for naming a table? ›

  • 1 Use singular nouns for tables. ...
  • 2 Use descriptive and meaningful names for columns. ...
  • 3 Use prefixes or suffixes for constraints. ...
  • 4 Use consistent naming conventions and case styles. ...
  • 5 Use abbreviations and acronyms sparingly and consistently. ...
  • 6 Here's what else to consider.
Mar 16, 2023

What are the rules for database names? ›

Database names must follow these rules: They must be unique within an installation. They must begin with an alphabetic character (not the underscore). No special characters other than the underscore, dollar sign, and at symbol (@) are allowed for regular identifiers.

What is an example of a naming convention? ›

Examples of naming conventions may include: Children's names may be alphabetical by birth order. In some Asian cultures, siblings commonly share a middle name. In many cultures the son is usually named after the father or grandfather.

What is the primary key naming convention in SQL? ›

A primary key is a field or a set of fields in the database table that uniquely identifies records in the database table. A table can have only one primary key. The naming conventions for a primary key constraint should have a "PK_" prefix, followed by the table name. The syntax should be "PK_<TableName>".

What is the best practice for user naming convention? ›

Determining a Naming Convention
  • Start with an alphabetic character.
  • Not contain spaces or “@”.
  • Be 30 characters or fewer for Mac or Linux, or 20 characters or fewer for Windows.
  • Contain only valid Unix Characters – letters, numbers, “-”, “.”, and “_”. ​
  • Be different from the device host name on Windows.

What is the unique key naming convention? ›

3 Answers
Index/Constraint TypeNaming Convention
Primary key<table-name> _PK
Unique index/constraint<table-name> _AK{xx}
Non-Unique index<table-name> _IX{xx}
Check constraint<table-name> _CK{xx}
2 more rows
Jan 29, 2011

Can a foreign key have the same name as the primary key? ›

Since each foreign key value must exactly match the corresponding primary key value, the foreign key must contain the same number and data type of columns as the primary key, and these key columns must be in the same order. A foreign key can also have different column names than the primary key.

How do I name a SQL table? ›

There are also a number of conventions which are enforced by the SQL engine. Though these vary somewhat between SQL “flavors”, SQL columns and table names should begin with a letter, not end in an underscore, and should contain only alphanumeric characters. Column and table names should not contain spaces.

Should SQL table names be singular or plural? ›

So Which Should I Use: Singular or Plural? The correct answer is that there is no right or wrong when naming database tables — just be consistent from the start. The only wrong answer with database table names is to use a combination of plural and singular.

Should SQL table names be capitalized? ›

SQL Table Letter-casing Conventions. For table names, you may use PascalCasing ( camelCasing with the first letter also capitalized) or lowercasing conventions, as long as you are consistent. In either case, table names should only contain alphabetic characters (no "_" or "-").

What is the naming convention for SQL databases? ›

Object names should be full English words. In general avoid abbreviations, especially if they're just the type that removes vowels. Most SQL databases support at least 30-character names which should be more than enough for a couple English words. PostgreSQL supports up to 63-character for identifiers.

What are the 5 database names? ›

MySQL, Oracle, PostgreSQL, Microsoft SQL Server, MongoDB, Redis, Elasticsearch, Cassandra, MariaDB, IBM Db2.

How to name a dataset in SQL? ›

Compatible naming conventions
  1. Only alphanum and underscore ( _ ).
  2. All lowercase characters.
  3. No spaces.
  4. Does not begin with a number.

What is the instance naming convention in SQL? ›

Instance names are limited to 16 characters. The first character in the instance name must be a letter. Acceptable letters are the ones defined by the Unicode Standard 2.0. These letters include Latin characters a-z, A-Z, and letter characters from other languages.

What is the best naming convention for MySQL? ›

Naming Conventions for MySQL
  • Embedded quotation marks are not permitted.
  • Case sensitivity is specified when a server is installed. ...
  • A name cannot be a reserved word in MySQL unless you enclose the name in quotation marks. ...
  • Database names must be unique.
Jun 17, 2024

What will be the naming convention of the SQL view generated? ›

For SQL naming, the qualified form is a schema-name followed by a period (.) and an SQL identifier. For system naming, the qualified form is a schema-name followed by a slash (/) followed by an SQL identifier1. The unqualified form of a view-name is an SQL identifier.

What is the correct naming convention for a variable? ›

A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables) There is no limit on the length of the variable name. A variable name cannot contain spaces.

Top Articles
How Hard Is It To Get a Walmart Credit Card?
How to Clear the npm Cache on Linux, macOS, and Windows
English Bulldog Puppies For Sale Under 1000 In Florida
Katie Pavlich Bikini Photos
Gamevault Agent
Pieology Nutrition Calculator Mobile
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Compare the Samsung Galaxy S24 - 256GB - Cobalt Violet vs Apple iPhone 16 Pro - 128GB - Desert Titanium | AT&T
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Craigslist Dog Kennels For Sale
Things To Do In Atlanta Tomorrow Night
Non Sequitur
Crossword Nexus Solver
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Hobby Stores Near Me Now
Icivics The Electoral Process Answer Key
Allybearloves
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
Marquette Gas Prices
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Vera Bradley Factory Outlet Sunbury Products
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Topos De Bolos Engraçados
Sand Castle Parents Guide
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Selly Medaline
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 5816

Rating: 4.3 / 5 (64 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.