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 automatically fills the field record. So am I correct in saying this mean I can remove the "NOT NULL" constraint for my primary keys?
(As you've tagged your question mysql
.) In MySQL, you don't have to do it explicitly. From the manual:
A
PRIMARY KEY
is a unique index where all key columns must be defined asNOT NULL
. If they are not explicitly declared asNOT NULL
, MySQL declares them so implicitly (and silently).
Of course, just because you don't have to doesn't mean you might not want to for clarity, etc.
Yes and no You can remove "Not null", that won't remove the constraint though. Personally I'd leave them in, you gain nothing worthwhile from taking them out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With