外键引用可以在PostgreSQL中包含NULL值吗?
发布时间:2020-12-13 16:16:02 所属栏目:百科 来源:网络整理
导读:举个例子 create table indexing_table( id SERIAL PRIMARY KEY,created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),); 下表之间有区别吗? 表格1: create table referencing_table( indexing_table_id INTEGER references indexing_table); 表2: create
举个例子
create table indexing_table ( id SERIAL PRIMARY KEY,created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),); 下表之间有区别吗? 表格1: create table referencing_table ( indexing_table_id INTEGER references indexing_table ); 表2: create table referencing_table ( indexing_table_id INTEGER references indexing_table NOT NULL ); 或者,在表1的情况下,没有NOT NULL约束,我们是否允许插入包含NULL值的记录?
对于表1,此INSERT语句将成功.如果你运行100次,它将成功100次.
insert into referencing_table values (null); 表2中的相同INSERT语句将失败. ERROR: null value in column "indexing_table_id" violates not-null constraint DETAIL: Failing row contains (null). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |