Re: problem referencing an attrib which is not unique - Mailing list pgsql-sql

From Richard Huxton
Subject Re: problem referencing an attrib which is not unique
Date
Msg-id 43E8ABEB.7000100@archonet.com
Whole thread Raw
In response to problem referencing an attrib which is not unique  (Vic Rowan <mightymate@gmail.com>)
List pgsql-sql
Vic Rowan wrote:
> CREATE TABLE event_msg (
>   event_id varchar(30) NOT NULL,
>   language char(2) NOT NULL,
>   predefined_msg varchar(250) NOT NULL,
>   PRIMARY KEY (event_id, language)
> );
> 
> CREATE TABLE logs (
>   id int NOT NULL,
>   event_id varchar(30) REFERENCES event_msg (event_id) NOT NULL,
>   placeholder_values varchar(250),
>   priority varchar(20) NOT NULL,
>   timestamp Date NOT NULL,
>   primary key (id)
> );
> 
> 
> The problem I am facing is the event_id from logs is not able to reference
> event_id from event_msg as its not unique.

The problem is with your event_msg table. You have two concepts - 
"event" and "event_msg_localised" but only one table.

The logs table should reference "event" (which has one row for each 
event and a unique event_id). The "event_msg_localised" table also 
references "event".

The event table might only contain the event_id primary-key, but I'd 
probably put a description in their for my own use (perhaps saying what 
values to expect).

HTH
--   Richard Huxton  Archonet Ltd


pgsql-sql by date:

Previous
From: Vic Rowan
Date:
Subject: problem referencing an attrib which is not unique
Next
From: Patrick JACQUOT
Date:
Subject: Re: problem referencing an attrib which is not unique