Reputation: 19203
I can use CREATE TABLE IF NOT EXISTS
to create a table only if it doesn't exist.
How can i do the same for CREATE INDEX..
to only create it if it doesn't exist?
Upvotes: 5
Views: 6313
Reputation: 489
You can do it as follows,
CREATE INDEX IF NOT EXISTS NEW_INDEX_NAME ON TABLE_NAME;
You can follow link aswell, http://www.h2database.com/html/grammar.html#create_index
Upvotes: 8
Reputation: 819
You could remove it if it exists.
DROP INDEX IF EXISTS IDXNAME
Then just add it afterward.
CREATE INDEX IDXNAME ON TEST(NAME)
I found it here H2 grammar
Upvotes: 1