Why you should be descriptive in naming your ID columns

Mattias te Wierik
4 min readJul 20, 2020
Photo by Caspar Camille Rubin on Unsplash

I had lately a heated discussion with a colleague about how we should name our primary key ID columns in our relational database. In this discussion there were two options: naming it plain id; or naming it tablenameId. In this article I will explain why I would advocate for the latter.

Let’s start with making the statement that this subject doesn’t have a right or wrong choice. Choosing for one of these doesn’t make you not conforming any convention and any bad engineer.

The first initial thought when seeing just an Id column would be that it’s simple and not too complicated. When writing queries just having to type on similar term every time makes it easy and not having to guess what the exact column would be to identity the entity.

SELECT * FROM Users WHERE Id = '72d0a246-1301-4544-8f37-35e4ffadabcf';SELECT * FROM Privileges WHERE Id = '052e14d9-1044-4149-9e01-49515515a0e2';

Seems simple, right? But what is the problem with this? The problem to arise when the amount of tables grow. For different use cases you will need to join tables to aggregate information. And this is where issues start to arrive.

Let’s take the previous stated queries as an example and build a user privilege system for a supermarket intranet. We want…

--

--