DEFAULT(col_name)
Returns the default value for a table column. If the column has no default value, NULL
is returned. For integer columns using AUTO_INCREMENT
, 0
is returned.
When using DEFAULT
as a value to set in an INSERT
or UPDATE
statement, you can use the bare keyword DEFAULT
without the parentheses and argument to refer to the column in context. You can only use DEFAULT
as a bare keyword if you are using it alone without a surrounding expression or function.
Select only non-default values for a column:
SELECT i FROM t WHERE i != DEFAULT(i);
Update values to be one greater than the default value:
UPDATE t SET i = DEFAULT(i)+1 WHERE i < 100;
When referring to the default value exactly in UPDATE
or INSERT
, you can omit the argument:
INSERT INTO t (i) VALUES (DEFAULT); UPDATE t SET i = DEFAULT WHERE i < 100;
© 2019 MariaDB
Licensed under the Creative Commons Attribution 3.0 Unported License and the GNU Free Documentation License.
https://mariadb.com/kb/en/default/