What's the point of adding NOT NULL to primary key field in MySQL?
They are the same. Primary key got NOT NULL
automatically.
You are asking, why do people bother adding the NOT NULL when it is unnecessary? Just because it is good style, I guess. And makes it explicit to the reader.
NULL
is not equivalent to NULL
(as NULL
indicates an unknown or absent value), so you will be permitted to have multiple records that have NULL
for the id, even though there's a primary key / unique constraint defined, hence the use of NOT NULL
. That's if MySql even allows you to define a primary key on a nullable field.
In addition, as a primary key is often used in a foreign key in other tables, having one or more NULL
values wouldn't make sense.