In mysql, which column defaults should I write, null or not null?

Asked 2 years ago, Updated 2 years ago, 38 views


Example) member_table
no - auto increment,
id - not null,
pw - not null,
email,  
phone,  
address 

For example, in the table above, only id and pw are required inputs I wonder if the e-mail, phone, and address columns give the default value not null, enter the syncquation when you insert, or just give the default value null when you insert, or subtract the column from the sql statement.

When selecting according to this basic setting, you have to decide whether to use where email!= NULL or where id!=', but some say that null does not use an index and looks through all columns.

It depends on the situation, but if there is a recommended method, please answer~

mysql

2022-09-22 22:03

1 Answers

I think you can decide whether to not null or null in the table when analyzing the domain.

For example, the email address should be not null if input is required. As another example, you can leave the address null if you do not need to enter it.

And if you look at the MySQL document, you'll find the following description.

NULL can be added to the index only in MyISAM, InnoDB, BDB, and MEMORY.

Finally, in SQL, the null check statement must be column IS NULL or column IS NOT NULL. Also, if you can omit the value input at the time of insert, you can declare the default value at the time of table creation.


2022-09-22 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.