Database, Table and Column Naming Conventions
Last Updated :
09 Aug, 2021
Overview :
Databases are persistent storage mechanisms that are present throughout the lifecycle of any application. Databases are created and maintained by the initial database managers and are continued to be maintained by any new database managers that join the team, thus it is a good habit to keep its characteristics consistent throughout. Naming conventions are a set of guideline that make strong foundations for such a consistent system. These guidelines ensure that the names of database entities are readable, easy to use in queries and do not collide with names of other defined entities or keywords.
Naming Databases :
When naming databases in a professional environment it mainly depends on what kind of application or website will the database belong to. Suppose you are creating a database for an application XYZ, for a company ABC, then the database would be named ABC_XYZ. Database names are easier to use when short, preferably using abbreviations (Facebook becomes FB), and need not be very descriptive. Building on the same point, IBM states in its documentation that database name or database alias should be a unique character string containing one to eight letters from the set of [a-z, A-Z, 0-9, @, #, $]. You can also add a product's version to the database name.
Naming Tables :
Tables represent a group/set of some entity that is usually a real-world object like an employee or consequences of that entity like a project. Tables names are like nouns. Different teams of developers follow different practices while naming their tables but some fundamentals are the key to efficiency. There are following steps for the Naming table are as follows.
Step-1 :
Table names should be descriptive. If you are designing a table to store the data about customers in a grocery shop then the table can be named "Customer" or "Customers" based on your preference. However, you should avoid abbreviations because different people may have different thought process while creating an abbreviation like "Cus" which may not always align with another person's naming like "Cust". So to keep things simple use full names and if you plan on using singular or plural names then that should remain consistent throughout the project.
#Creating table Customer
CREATE TABLE Customer (column1 datatype, column2 datatype, column3 datatype, ....);
Step-2 :
You can use underscores to prefix a table name. For example, all vegetarian food tables can be written as "Veg_Food" and non-vegetarian can be written as "NonVeg_Food."
Step-3 :
Avoid using DBMS-specific keywords as names for your tables like "Order" (ORDER BY). The server or the RDBMS won't throw any error while naming a table as "Order" but it is a good practice.
Step-4 :
Casing depends all on what the developer prefers and what has been used consistently before. But similar to the singular-plural dilemma, you should stick to one case whichever looks readable and easy on the eyes, either it be PascalCase or camelCase or all lowercase etc.
CREATE TABLE OldMansions (column1 datatype, column2 datatype, column3 datatype, ....);
CREATE TABLE oldMansions (column1 datatype, column2 datatype, column3 datatype, ....);
CREATE TABLE oldmansions (column1 datatype, column2 datatype, column3 datatype, ....);
CREATE TABLE old_mansions (column1 datatype, column2 datatype, column3 datatype, ....);
Naming Columns :
Columns are different than tables as they can mean more than just a real-world entity. Columns are the attributes that define a real-world entity. Columns may define the departure time of a train or the distance of a planet from the sun, or simply someone's name. Thus, it is common sense to name a column corresponding to its use. Column names are like adjectives or verbs. There are the following steps for Naming columns are as follows.
Step-1 :
Each column name should be unique. If two columns from different tables serving different purposes are in the same database then use some kind of prefixes that separate the two.
Owner | Old_Boats | New_Boats |
---|
01 | BO-25 | BO-102 |
02 | BO-26 | BO-103 |
03 | BO-27 | BO-104 |
04 | BO-25 | BO-101 |
Step-2 :
Column names must not be abstract or cryptic. Use long descriptive names instead of short and unclear abbreviations.
Step-3 :
The column names must not be very generic. For example, while creating a column that stores the codes of grocery items it would be better to name the column "Grocery_Code" or "ItemCode" instead of just "Code." You can have a quick look at this column to add suffixes with a specific domain's prefixes.
Class | Suffix |
---|
Code | _CD or _CODE |
Description | _DESC |
Percentage | _PCT |
Balance | _BAL or _BALANCE |
Amount | _AMT or _AMOUNT |
Frequency | _FREQ |
Index | _IDX |
Naming Primary Keys :
- Primary keys serve as the unique identifier for your table, thus it is important to be careful while naming them. If several different tables with different uses have the same name for their respective primary key then it would be very confusing.
- Make sure that instead of naming a primary key representing an identity number as ID, use domain-specific names like StudentID or ID_Student.
- You can also use suffixes or prefixes with your primary keys to making them stand out from the general column naming. For example, Coordinates_PK or PK_Coordinates.
Naming Foreign Keys :
- Foreign keys are used as a bridge between two tables, and sometimes among more tables. Thus, it is good to name your foreign key with the same name consistently throughout the database to avoid any confusion.
- Similar to primary keys, you can add prefix or suffix to a foreign key name, like RoomNo_fk or FK_RoomNo.
- At the end of the day, no one is going to force you to follow these conventions while creating a database. But following even some of these will make your database better for you as well as anyone else who might work on it in the future.
Similar Reads
Components of Table in Database
In the changing world of a database, tables are the fundamental structures that organize and save data with precision. A table, in the context of a database, is a scientific arrangement of records offered in rows and columns. It improves the performance of information control and retrieval. In this
4 min read
What are Naming Conventions for MongoDB?
MongoDB is a popular NoSQL database management system known for its flexibility and scalability. One important aspect of MongoDB development is proper naming conventions. These conventions ensure consistency, clarity, and readability across databases and applications. In this article, We will learn
4 min read
How to Rename a Column Name in MariaDB?
MariaDB is an open-source relational database management system that can be used to create databases, and tables and to query the tables. Anyone who knows how to write SQL queries can use any of the databases like MariaDB or Mysql for the execution of SQL queries. In this article, we will learn abou
4 min read
What is a Columnar Database?
Columnar databases are those where the data is stored in columns instead of rows as is done in the traditional row-based databases as they offer impressive benefits in certain types of queries and data manipulation operations. Therefore, databases that are organized in columns provide better perform
3 min read
PostgreSQL - Naming Conventions
PostgreSQL naming conventions provide guidelines for naming database object names in PostgreSQL, including tables, columns, indexes and constraints. In this article, We will learn about essential naming conventions such as PostgreSQL table naming, index naming and primary key naming to promote best
3 min read
Column and Data Types in SQLAlchemy
SQLAlchemy is an open-source library for the Python programming language that provides a set of tools for working with databases. It allows developers to interact with databases in a more Pythonic way, making it easier to write code that is both efficient and readable. Column TypesA column type in S
4 min read
Composite Key in Database
A database is a structured collection of data organized and stored electronically in a computer system. It is designed to efficiently manage, retrieve, and manipulate large volumes of data according to specific requirements and criteria. In a relational database, the key plays an important role. The
6 min read
How to Design a Database for Content Management System (CMS)
A content management system is a computer application that allows publishing, editing, and modifying content, organizing, deleting as well as maintenance from a central interface. An RDBMS is reliable in storing and managing the content of a CMS to a large extent due to its regional database. In thi
6 min read
Creating APIs for Relational Database
In the era of software development, relational databases stand as pillars of structured data storage and organization. These databases, with their tables, rows, and columns, provide a reliable framework for managing information. But what makes them truly powerful is their collaboration with APIs, th
8 min read
How to Design a Database for Web Applications
Web applications have become ubiquitous, powering various online services and platforms across industries. Behind the seamless functionality of web applications lies a well-designed database architecture capable of storing, retrieving, and managing data efficiently. In this article, we will explore
4 min read