1

I want to insert rows if nothing exists in a table.

Something like that:

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

But it causes Error: SQLITE_ERROR: near "WHEN": syntax error

1 Answers1

-1

You could use:

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

db<>fiddle demo

Lukasz Szozda
  • 162,964
  • 23
  • 234
  • 275