If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Other > Problem with foreign keys in DerbyDB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-06, 09:01
Lukas_Adamek Lukas_Adamek is offline
Registered User
 
Join Date: Aug 2004
Posts: 3
Problem with foreign keys in DerbyDB

Hi

I have 2 tables:

CREATE TABLE users (
id_user INTEGER NOT NULL GENERATED
ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
name VARCHAR(30),
PRIMARY KEY (id_user)
);

CREATE TABLE articles (
id_article INTEGER NOT NULL GENERATED
ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
creator SMALLINT NOT NULL,
PRIMARY KEY (id_article)
FOREIGN KEY (creator) REFERENCES users (id_user)
);

Second table doesn`t create.
Error message is:

ERROR X0Y44: Constraint 'SQL061110025111171' is invalid: there is no unique or primary key constraint on table 'APP.UZIVATELE' that matches the number and types of the columns in the foreign key.

Where is the problem?
Reply With Quote
  #2 (permalink)  
Old 11-11-06, 05:01
Lukas_Adamek Lukas_Adamek is offline
Registered User
 
Join Date: Aug 2004
Posts: 3
Solution

The reason is:
id_user is INTEGER
creator is SMALLINT
and INTEGER nad SMALLINT are non-full-compatible types.

If creator is INTEGER, all is OK.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On