How important are constraints like NOT NULL and FOREIGN KEY if I'll always control my database input with PHP?

后端 未结 15 2298
我在风中等你
我在风中等你 2021-02-04 01:14

I am trying to create a column in a table that\'s a foreign key, but in MySQL that\'s more difficult than it should be. It would require me to go back and make certain changes

15条回答
  •  萌比男神i
    2021-02-04 01:40

    The most important thing about using NOT NULL to me, is more the documentation part. When I return to the project after a few months I forget which columns it is acceptable to have nulls in. If the column says NOT NULL, then I know I will never ever have to deal with potential null values from it. And if it allows null, then I know for sure I have to deal with them.

    The other thing is, as others have noted: You may miss something somewhere, and cleaning up data sucks, or may be entirely impossible. It's better to know for sure that all data in your database is consistent.

提交回复
热议问题