如何在SQL表中插入默认值? [英] How to insert default values in SQL table?
本文介绍了如何在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
.
这篇关于如何在SQL表中插入默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文