A
A
Anton2019-03-30 14:46:29
PostgreSQL
Anton, 2019-03-30 14:46:29

What will happen to the primary key if you create a table without specifying PRIMARY KEY?

I have created tables with explicit indication of the primary key for the column, and without specifying the primary key at all. But the primary key is mandatory for every table. Is it set automatically? If yes, then where? For the first column?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Melkij, 2019-03-30
@Anton238

But primary key is required for every table

From the point of view of relational theory and normal forms in particular.
From the point of view of SQL - it is not obligatory. A table may not declare a primary key, or even some unique key. Next are the implementation details.
In PostgreSQL, even a surrogate primary key will not be created in this case. Row addressing in PostgreSQL is performed by TID (tuple ID) - the physical address of the row in the datafile (and therefore the TID is unique in the table), including when searching by the primary key. But TID is not an index, has nothing to do with the stored data and does not impose any restrictions on the data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question