Mam następujący schemat:
CREATE TABLE Languages(
langid serial PRIMARY KEY,
lang text UNIQUE NOT NULL
);
CREATE TABLE Translations(
langid integer REFERENCES Languages(langid),
textid serial,
translation text NOT NULL,
PRIMARY KEY(langid,textid)
);
CREATE TABLE Items(
itemid serial PRIMARY KEY,
name integer REFERENCES Translations(textid)
);
CREATE TABLE ItemBody(
itemid integer REFERENCES Items(itemid)ON DELETE cascade,
position integer,
textid integer REFERENCES Translations(textid),
body text,
CHECK((textid isnull) <> (body isnull)),
PRIMARY KEY(itemid,position)
);
<font size="1">napisane w PostgreSQL, ale generalnie może być SQL</span>
I teraz dla danego itemid chcę zaznaczyć wszystkie języki (Languages) na które może on zostać przetłumaczony.
tzn: Istnieją odpowiednie krotki w relacji Translations dla Items.name i dla każdego ItemBody.textid gdzie nie jest on null'em