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

编程入门 行业动态 更新时间:2024-10-28 11:19:31
本文介绍了如何在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 和 field4 ,并将5分配给 field1 ,将10分配给 field3 。

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

更多推荐

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

本文发布于:2023-10-22 08:04:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516934.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:默认值   如何在   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!