Naming convention for PK & Username column of user info tables

Introduction

I have to make a decision of naming ID column with .ID or .SEQ_NM such like that.

I used to name the ID columns of oracle tables with ID for years.

Recently, I’ve seen someone’s code in which ID columns named with SEQ_NM and Username columns named with USER_ID.

It stired my own naming convention rule. I rethought it with my own rule and that is like as below.

The Advantage of my rule

1. Tell PK and linked FK apart in sql query easily.

SELECT
    T1.ID, T1.NAME, T1.NICKNAME, T2.NAME
FROM TB_USER T1
    INNER_JOIN TB_DEPART T2 ON T1.ID = T2.USER_ID;

2. Constancy of PK column in all tables.

TB_USER.ID
TB_DEPART.ID
TB_ACTION.ID
...

The Disadvantage

  1. Confusion with User table’s ID(PK) and User-ID (Username)
    It looks very long and complex when I see TB_USER.USERNAME in query, what about you?
    Because of that, I usally prefer USER_ID or UUID instead of USERNAME.
    When i use USER_ID it can be confused with foreign keys to TB_USER table.

I have difficulty with this, and want to hear the opinions of you, brothers.
Any opinion or reply would be appreciate for me. Thanks.

Related Post