Quick SQL question: Correct syntax for creating a table with a primary key in H2? Quick SQL question: Correct syntax for creating a table with a primary key in H2? sql sql

Quick SQL question: Correct syntax for creating a table with a primary key in H2?


If I'm reading the H2 documentation correctly, this should work:

CREATE TABLE MyTableName(PKFieldName IDENTITY PRIMARY KEY, StringFieldName VARCHAR(255))

Basically, you just want to declare your key column to be of type IDENTITY.

For IDENTITY type see: http://www.h2database.com/html/datatypes.html#identity_type
For CREATE TABLE syntax see: http://www.h2database.com/html/grammar.html#create_table