DEFAULT

2026-02-11 07:43:39  Updated

Syntax

DEFAULT(col_name)

Purpose

DEFAULT() returns the default value of a column. If the specified column does not have a default value, the function returns NULL.

Examples

obclient> CREATE TABLE t1 (id INT, i INT DEFAULT 1);
Query OK, 0 rows affected
obclient> INSERT INTO t1 VALUES (1,3);
Query OK, 1 row affected
obclient> UPDATE t1 SET i = DEFAULT(i)+1 WHERE id < 100;
Query OK, 1 row affected
Rows matched: 1  Changed: 1  Warnings: 0
obclient> SELECT * FROM t;
+------+------+
| id   | i    |
+------+------+
|    1 |    2 |
+------+------+
1 row in set

obclient> CREATE TABLE t2 (id INT, i INT);
Query OK, 0 rows affected
obclient> INSERT INTO t2 VALUES (1,3);
Query OK, 1 row affected
obclient> UPDATE t2 SET i = DEFAULT(i)+1 WHERE id < 100;
obclient> SELECT * FROM t2;
+------+------+
| id   | i    |
+------+------+
|    1 | NULL |
+------+------+
1 row in set

Contact Us