Mysql set to default?

Mar 12, 2012   //   by phpfreelancer.biz   //   Blog, MySQL Tutorial  //  No Comments

Use the keyword DEFAULT to set a column explicitly to its default value. This makes it easier to write INSERT statements that assign values to all but a few columns,

because it enables you to avoid writing an incomplete VALUES list that does not include a value for each column in the table. Otherwise, you would have to write out the list of column names corresponding to each value in the VALUES list.

You can also use DEFAULT(col_name) as a more general form that can be used in expressions to produce a given column’s default value

DEFAULT(col_name) can only be used if a default is explicitly set for that column, but DEFAULT should always work.

UPDATE accounts SET thisColumn = DEFAULT WHERE id = ?

Leave a comment

Share This Post

RSS Wordpress News