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.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top