Home > Database > Mysql Tutorial > body text

How to specify default value in MySQL INSERT statement?

WBOY
Release: 2023-09-15 20:29:06
forward
1148 people have browsed it

如何在 MySQL INSERT 语句中指定默认值?

While creating the table, if any column has a default value defined, then by using the keyword "DEFAULT" in the INSERT statement, we can get the default value for that column. For example, we have created a table "employee" with default value as column "DOJ" as shown below -

mysql> Create table employee(id int, name varchar(20), doj date DEFAULT '2005-01-01');
Query OK, 0 rows affected (0.09 sec)

mysql> Insert into employee(id, name, doj) values(1, ’Aarav’, DEFAULT);
Query OK, 1 row affected (0.03 sec)

mysql> select * from employee;
+------+------------+---------------+
| id   | name       | doj           |
+------+------------+---------------+
| 1    |Aarav       | 2005-01-01    |
+------+------------+---------------+
1 row in set (0.00 sec)
Copy after login

As can be seen from the above query, when we insert the value using DEFAULT keyword, MySQL inserts the default value specified when defining the column.

The above is the detailed content of How to specify default value in MySQL INSERT statement?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!