H2 SQL database - INSERT if the record does not exist
I would like initialize a H2 database, but I am not sure if the records exist. If they exist I don't want to do anything, but if they don't exist I would like to write the default values. Something like this: IF 'number of rows in ACCESSLEVELS' = 0 INSERT INTO ACCESSLEVELS VALUES (0, 'admin'), (1, 'SEO'), (2, 'sales director'), (3, 'manager'), (4, 'REP') ; The following works for MySQL, PostgreSQL, and the H2 database: drop table ACCESSLEVELS; create table ACCESSLEVELS(id int, name varchar(255)); insert into ACCESSLEVELS select * from ( select 0, 'admin' union select 1, 'SEO' union select 2,