D
D
driverx182017-09-02 03:12:14
Database
driverx18, 2017-09-02 03:12:14

Should there always be an ID column in a database table?

I've been thinking about this question. How many tutorials I watched on creating sites, everyone always had the same auto-incrementing primary key ID column, I do any projects, I always enter IDs, even the Laravel framework itself automatically enters $table->increments('id') when creating migrations;
Even the situation: there is a TEAM sign that lists just 10 employees of the company, and you need to bring them all to the "Team" page of the site. I imagine the structure of the database like this: full name, age, position, a little about the employee. Then just select ALL rows from the database and push them into the view (that is, ID is not needed here, we are not referring to a specific person with an ID, but immediately select all without exception)
Or am I wrong? Or is the ID always needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fortop, 2017-09-02
@driverx18

If we consider mysql innodb, then even if you do not add an id, in the absence of a primary key, a system (hidden for you) primary key will be created.
As for the ID specifically, no, this particular column in the table is not required.
But it is highly desirable to have a primary key. Its role can be played by another column (or several) containing unique data that uniquely identifies the record

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question