如何在SQL表中插入默认值?

问题描述:

我有一个这样的表:

create table1 (field1 int,
               field2 int default 5557,
               field3 int default 1337, 
               field4 int default 1337)

我要插入

我尝试将插入到table1值(5,null,10,null)中无效,并且 ISNULL(field2,default)也无效。

I've tried insert into table1 values (5,null,10,null) but it doesn't work and ISNULL(field2,default) doesn't work either.

当我插入行时,如何告诉数据库使用列的默认值?

How can I tell the database to use the default value for the column when I insert a row?

不要在insert语句中包括要使用默认值的列。例如:

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);

...将采用 field2 $ c $的默认值c>和 field4 ,并将5分配给 field1 ,将10分配给 field3

...will take the default values for field2 and field4, and assign 5 to field1 and 10 to field3.