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
- Confusion with User table’s ID(PK) and User-ID (Username)
It looks very long and complex when I seeTB_USER.USERNAME
in query, what about you?
Because of that, I usally preferUSER_ID
orUUID
instead ofUSERNAME
.
When i useUSER_ID
it can be confused with foreign keys toTB_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.