如果不存在则插入

时间:2018-09-18 18:44:53

标签: sql sqlite

如果表中不存在行,我想插入行。

类似的东西:

WHEN NOT EXISTS (SELECT * FROM Students) THEN
INSERT INTO Students (name) VALUES ("Foo Bar"), ("Bar Foo")

但这会导致Error: SQLITE_ERROR: near "WHEN": syntax error

1 个答案:

答案 0 :(得分:-1)

您可以使用:

INSERT INTO Students (name) 
SELECT * FROM (VALUES ("Foo Bar"), ("Bar Foo"))
WHERE NOT EXISTS(SELECT * FROM Students);

db<>fiddle demo