daniels
daniels

Reputation: 19203

H2: how to tell if index exists?

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

Answers (2)

Niru
Niru

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

Jeff Anderson
Jeff Anderson

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

Related Questions