php - In MySQL tables is it important to assign a default value to a column and why? -



php - In MySQL tables is it important to assign a default value to a column and why? -

when update rows in mysql table warning "field xyz doesn't have default value". true; doesn't. validate info obtained mysql in php code.

the fact mysql warns me makes me wonder: of import have default values assigned columns , if so, why? performance? predictable behavior? simplification of calling code? other best practices or issues i'm not aware of?

apparently, declaring columns not null. allowed , reasonable. however, when insert new row table, mysql needs know value is. here 3 ways can set in value:

in insert statement, can explicitly list value. in create table statement, can have default value. null default if none listed. the table can have insert trigger specifies values columns.

because mysql utilize null default, getting error when null not allowed in column.

edit:

the original reply not 100% complete, because mysql create values when used in normal mode. these described here in documentation. so, right 4th bullet is:

mysql insert default values of 0 numerics , '' strings under most, not all, circumstances

because circumstances pretty broad, operating in strict mode or have default behavior turned off.

php mysql validation default

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -