Hi,

According to my test, if you create the tables in the wrong order, HSQLDB
will also throw an exception.

In addition to the order of tables, the syntax "... KID int FOREIGN KEY
REFERENCES KUNDE(KID),..." is not currently supported in H2. It is also not
supported in PostgreSQL, Apache Derby, SQLite.

The following syntax is supported by most databases:

drop table reservierung;
drop table box;
drop table kunde;

CREATE TABLE BOX
(BID int PRIMARY KEY,
Groesse int,
Einstreu varchar(50),
Ort varchar(50),
Fenster boolean,
Preis int,
Bild varchar(50));

CREATE TABLE RESERVIERUNG
(RID int PRIMARY KEY,
KID int,
BID int,
Anfang date,
Ende date,
Pferd varchar(50)
);

CREATE TABLE Kunde
(KID int PRIMARY KEY,
 Name varchar(50),
 HatKundenKarte boolean
);

alter table  reservierung add foreign key(bid) references box(bid);
alter table  reservierung add foreign key(kid) references kunde(kid);

Regards,
Thomas


On Thursday, October 15, 2015, Ryan How <[email protected]> wrote:

> You need to create the Kunde table before the RESERVIERUNG table.
> Otherwise it can't create the foreign key (because the table doesn't exist).
>
>
> On 15/10/2015 6:04 PM, Steve McLeod wrote:
>
> Two things I can suggest:
>
> 1) You should ask this question on stackoverflow.com, not in this mailing
> list.
> 2) You should post the full error you get (on stackoverflow.com)
>
>
> On Thursday, 15 October 2015 05:42:59 UTC+2, DBDude wrote:
>>
>> Hi!
>>
>> I have a problem with creating tables:
>> CREATE TABLE BOX
>> (BID int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
>> Groesse int,
>> Einstreu varchar(50),
>> Ort varchar(50),
>> Fenster boolean,
>> Preis int,
>> Bild varchar(50));
>>
>> CREATE TABLE RESERVIERUNG
>> (RID int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
>> KID int FOREIGN KEY REFERENCES KUNDE(KID) ,
>> BID int FOREIGN KEY REFERENCES BOX(BID),
>> Anfang date,
>> Ende date,
>> Pferd varchar(50),
>> );
>>
>>
>> CREATE TABLE Kunde
>> (KID int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
>>  Name varchar(50),
>>  HatKundenKarte boolean,
>> );
>>
>> When I execute this sql statement I cant create the table 'reservierung'
>> . There seems to be a problem with the 'foreign key references' command.
>> I used this code with HSQLDB a while ago and it worked. Does anyone know
>> what is wrong with the code?
>>
> --
> 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 [email protected]
> <javascript:_e(%7B%7D,'cvml','h2-database%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> 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 [email protected]
> <javascript:_e(%7B%7D,'cvml','h2-database%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Reply via email to