SQLite Forum

Bug in multiple Primary key inserting null.
Login

Bug in multiple Primary key inserting null.

(1) By anonymous on 2020-04-06 13:50:12 [link] [source]

When creating a table with multiple Primary Key , then inserting into columns that are primary key with one null value or all of them was null , the records inserting without error ! but that is a constraint violation! example :

create table if not exists tbl2 (
name TEXT ,
last_name TEXT ,
PRIMARY KEY (name,last_name)
);
insert into tbl2 values('s','g');
// inserting above value again throws error
// but
insert into tbl2 values('s',null);
// inserting above value again it doesn't throws error
// or below insert
insert into tbl2 values(null,null)

(2) By Richard Hipp (drh) on 2020-04-06 13:55:20 in reply to 1 [source]

See https://sqlite.org/quirks.html#primary_keys_can_sometimes_contain_nulls for an explanation of why this is happening.