Mega Code Archive

 
Categories / MySQL Tutorial / Insert Update Delete
 

Use the DEFAULT in the insert statement

mysql> mysql> CREATE TABLE myTable(     ->    ID TINYINT UNSIGNED NOT NULL DEFAULT 1,     ->    Name VARCHAR(50) NOT NULL     -> ); Query OK, 0 rows affected (0.03 sec) mysql> mysql> INSERT INTO myTable (ID, Name)VALUES (1,'A'),(DEFAULT,'B'); Query OK, 2 rows affected (0.00 sec) Records: 2  Duplicates: 0  Warnings: 0 mysql> mysql> select * from myTable; +----+------+ | ID | Name | +----+------+ |  1 | A    | |  1 | B    | +----+------+ 2 rows in set (0.00 sec) mysql> mysql> drop table myTable; Query OK, 0 rows affected (0.01 sec) mysql>