unique index versus primary key

57 views
Skip to first unread message

willy

unread,
Nov 21, 2021, 4:07:10 AM11/21/21
to h2-da...@googlegroups.com
Hi,

The following works in 1.4.200, but gives the following error in
1.4.201   :
Any ideas ?

Kind regards

Willy

 Constraint "PRIMARY KEY | UNIQUE (TYPES)" not found; SQL statement:
CREATE  TABLE FCOUNTS(     ID IDENTITY primary key ,     NR VARCHAR,    
NAME VARCHAR,     TYPES VARCHAR,     TAG VARCHAR, Foreign key(types)
references ftypes(types),     Foreign key(tag) references ftags(tag) )

Code :

create  table ftypes(
    ID IDENTITY primary key ,
    types VARCHAR
);

create unique index ftype_idx on ftypes(types);

create  table ftags(
    ID IDENTITY primary key ,
    tag VARCHAR
);
create unique index ftag_idx on fintags(tag);


CREATE  TABLE FCOUNTS(
    ID IDENTITY primary key ,
    NR VARCHAR,
    NAME VARCHAR,
    TYPES VARCHAR,
    TAG VARCHAR,
    Foreign key(types) references ftypes(types),
    Foreign key(tag) references ftags(tag)
);

Andrei Tokar

unread,
Nov 23, 2021, 8:51:17 AM11/23/21
to H2 Database
I wonder if that's because of create unique index ftag_idx on fintags(tag);
contains invalid table name?

Gmail

unread,
Nov 23, 2021, 9:02:41 AM11/23/21
to h2-da...@googlegroups.com, Andrei Tokar
Hi,

sorry wrong cut/paste

Still the same error :
Constraint "PRIMARY KEY | UNIQUE (TYPES)" not found; SQL statement:
CREATE  TABLE FCOUNTS(     ID IDENTITY primary key ,     NR VARCHAR,     NAME VARCHAR,     TYPES VARCHAR,     TAG VARCHAR,     Foreign key(types) references ftypes(types),     Foreign key(tag) references ftags(tag) ) [90057-200]



create  table ftypes(
    ID IDENTITY primary key ,
    types VARCHAR
);

create unique index ftype_idx on ftypes(types);

create  table ftags(
    ID IDENTITY primary key ,
    tag VARCHAR
);
create unique index ftag_idx on ftags(tag);



CREATE  TABLE FCOUNTS(
    ID IDENTITY primary key ,
    NR VARCHAR,
    NAME VARCHAR,
    TYPES VARCHAR,
    TAG VARCHAR,
    Foreign key(types) references ftypes(types),
    Foreign key(tag) references ftags(tag)
);
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/3d57f368-0b7a-4960-81ec-4cdc82ab4b3an%40googlegroups.com.

Andrei Tokar

unread,
Nov 23, 2021, 4:56:10 PM11/23/21
to H2 Database
Please note that it is complaining about missing constraint. Indeed, you create a unique index, but not a unique constraint, which is required for referential integrity constraint.
If instead you define table as
create table ftypes(ID IDENTITY primary key , types VARCHAR UNIQUE );
it will generate a constraint (and index shouldl be created automatically), and everything just works.

Gmail

unread,
Nov 24, 2021, 5:03:25 AM11/24/21
to h2-da...@googlegroups.com, Andrei Tokar
Hi,

This is what I need,
Where can I find a document whith changes between 1.4.200 and 1.4.201 ?

Thanks a lot

Willy
Reply all
Reply to author
Forward
0 new messages