Domanda

I'm implementing a DB for a project I'm doing in my research and, after using some AUTO_INCREMENTS I got curious... Once the AUTO_INCREMENT is already automatically inserting a value in the column, why do we need to put the NOT NULL together?

Example:

user_id INT NOT NULL AUTO_INCREMENT

Thanks.

È stato utile?

Soluzione

You don't have to specify NOT NULL on the column definition with AUTO_INCREMENT.

You can leave it off, and MySQL will make the column NOT NULL.

And if you specify NULL in place of NOT NULL, MySQL will accept the syntax, but it will ignore that, and make the column NOT NULL anyway.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top