How to insert default values in SQL table?
Just don't include the columns that you want to use the default value for in your insert statement. For instance:
INSERT INTO table1 (field1, field3) VALUES (5, 10);
...will take the default values for field2
and field4
, and assign 5 to field1
and 10 to field3
.
This works if all the columns have associated defaults and one does not want to specify the column names:
insert into your_table
default values
Best practice it to list your columns so you're independent of table changes (new column or column order etc)
insert into table1 (field1, field3) values (5,10)
However, if you don't want to do this, use the DEFAULT
keyword
insert into table1 values (5, DEFAULT, 10, DEFAULT)