mysqldatabaseconstraintsprimary-keynotnull

What's the point of adding NOT NULL to primary key field in MySQL?


What's the point of adding NOT NULL to a primary key field? Primary key is already not null + unique.

Here is an example:

CREATE TABLE student (
  id int(11) AUTO_INCREMENT NOT NULL,
  name varchar(255),
  PRIMARY KEY(id)
)

Why not to define it like this instead:

CREATE TABLE student (
  id int(11) AUTO_INCREMENT,
  name varchar(255),
  PRIMARY KEY(id)
)

Solution

  • They are the same. Primary key got NOT NULL automatically.