N
N
Nikolai Kokoulin2019-04-22 13:42:29
SQL
Nikolai Kokoulin, 2019-04-22 13:42:29

What is the name of the primary key?

I argued with a colleague about the name of the key, he speaks for a meaningful name that reveals the essence of the column, but I think that the primary key, in most cases, should be called ID.
the meaning of the field (as well as the primary key) is to be an identifier of this record in the table
to make it easier, the colleague suggests that the fields be conditionally book_code, although this is a normal auto-increment column
Please tell us what is the truth (:

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Mirilaczvili, 2019-04-22
@2ord

I think that the primary key, in most cases, should be called ID.
I agree.
There is no point in being smart.

T
TheRonCronix, 2019-04-22
@TheRonCronix

A non-composite key as a column can be called simply id, you can name_table_id. In my opinion, both options are acceptable.
It is important to stick to one standard as soon as possible, because This will have a positive effect on various types of automation.
table_id_name can be more beneficial if you have two different tables but semantically have the same primary key. Those. It has only one business sense. Also in selections where short one-two letter sequences are used as aliases and several id are selected, it can be difficult to understand which id is from which table. In general, I lean towards the option with meaningful names, because a meaningful name is better than a non-meaningful one; I would choose table_name_id.
It makes sense to call the primary key itself as a constraint: pk_table_name

D
Denis, 2019-04-22
@sidni

If the field is auto-incremental or randomly generated by type uid, guid, then I call it id, if the field is generated according to some condition, then I call it meaning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question