MySQL - Are “NOT NULL” constraints needed for primary keys?

前端 未结 4 616
轮回少年
轮回少年 2021-01-04 04:15

is it necessary to declare \"NOT NULL\" constraints for primary keys in the MySQL database? A primary key cannot have NULL values because it auto_increments anyway and auto

4条回答
  •  自闭症患者
    2021-01-04 04:25

    Primary key must not include nullable columns. auto_increment is not a check constraint, (it is rather a default constraint) , so you cannot remove not null from definition of the column that is part of primary key regardless of presence of auto_increment. You don't have to type not null while creating the table for primary key in mysql, because the engine adds this constraint automatically.

提交回复
热议问题