SQLite默认值,如果为null [英] SQLite default value if null
问题描述
假设我有一个名为表的表
Let's say I have a table called "table"
所以
Create Table "Table" (a int not null, b int default value 1)
如果我做一个 INSERT INTO Table(a)值(1)
。我将为a列返回1,为b列返回1,因为b列的默认值为1。
If I do a "INSERT INTO "Table" (a) values (1)
". I will get back 1 for column a and 1 for column b as the default value for column b is 1.
但是如果我执行 INSERT INTO表格(a,b)值(1,空)
。我将为a列投注1,为b列投注一个空值。如果给出了空值,是否可以设置列的默认值?
BUT if I do "INSERT INTO "Table" (a, b) values (1, null)
". I will bet back 1 for column a and an empty value for column b. Is there a way to set a column's default value if a null was given?
推荐答案
否,如果您正在这样做:
No, if you are doing:
INSERT INTO my_table (a, b) values (1, null)
您明确地要求上的
列。 空
值b
You are explicitely asking for a null
value on b
column.
在RDBMS中,从技术上讲,您可以使用触发器来覆盖该行为。但是在SQLite中,你做不到。
In a RDBMS you could technically use a trigger to override that behavior. But in SQLite you can't.
这篇关于SQLite默认值,如果为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!