Composite primary key definition syntax in the H2 Database engine

Asked

Viewed 213 times

-1

I am trying to define a primary key composed of two columns when creating a table in the H2 Database Engine (http://www.h2database.com/html/main.html), but I couldn’t find the syntax in the manual. For example: the syntax in Mysql, Postgress... Maybe some of it works...

I tried to:

CREATE TABLE CONTACORRENTE (AGENCIA INT PRIMARY KEY, NUMERO INT PRIMARY KEY)

But H2 does not recognize as a composite key (it says that it is not possible to define two primary keys).

  • 1

    Nothing like the documentation: https://www.h2database.com/html/grammar.html#Constraint

1 answer

1


Try it like this:

CREATE TABLE  CONTACORRENTE (
    Agencia INT NOT NULL,
    Numero  INT NOT NULL,

 CONSTRAINT [PK_CONTACORRENTE] PRIMARY KEY (
    Agencia,Numero 
 )
)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.