keithphw
keithphw

Reputation: 390

h2 sql, create table with multi-column primary key?

How can i create a multi-column primary key within the CREATE TABLE statement using the h2 database? From my investigations, the code to do so in mySQL and Apache Derby databases is:

CREATE TABLE SAMP.SCHED(
    CLASS_CODE CHAR(7) NOT NULL, 
    DAY SMALLINT NOT NULL, 
    STARTING TIME, 
    ENDING TIME,
    PRIMARY KEY (CLASS_CODE, DAY));

But this doesn't work in h2, it results in a 'org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement'

Any help is much appreciated. Thanks

Upvotes: 14

Views: 29663

Answers (1)

icyrock.com
icyrock.com

Reputation: 28598

From here:

this should work:

ALTER TABLE SAMP.SCHED ADD PRIMARY KEY (CLASS_CODE, DAY)

Upvotes: 13

Related Questions