foreign key constraint to multiple tables
От
Kevin McCarthy
Тема
foreign key constraint to multiple tables
Дата
Msg-id
4178da10708130914x1f5b0304p21f4ed63f08c7fb5@mail.gmail.com
Список
Дерево обсуждения
foreign key constraint to multiple tables "Kevin McCarthy" <kemccarthy1@gmail.com>
Re: foreign key constraint to multiple tables Oliver Elphick <olly@lfix.co.uk>
I have a table with a column that will join with one of several tables based on the value of another column. I'm not sure if this column can be set as a foreign key to any of these tables, may be simply bad design on my part. The item_type_id column of a record of 'A' will reference one of the 'type' table records depending upon what the value of the record's item_type column is.
Is there a way to set the item_type_id column in Table A as a foreign key to the other tables depending? Or would there be a better way to design this schema?
TIA
CREATE TABLE ABC(
id SERIAL PRIMARY KEY,
item_type character varying(10) NOT NULL,
item_type_id INTEGER
);
CREATE TABLE typeA(
typeA_id SERIAL PRIMARY KEY
);
CREATE TABLE typeB(
typeB_id SERIAL PRIMARY KEY
);
CREATE TABLE typeC(
typeC_id SERIAL PRIMARY KEY
);
--
Kevin McCarthy
kemccarthy1@gmail.com
Is there a way to set the item_type_id column in Table A as a foreign key to the other tables depending? Or would there be a better way to design this schema?
TIA
CREATE TABLE ABC(
id SERIAL PRIMARY KEY,
item_type character varying(10) NOT NULL,
item_type_id INTEGER
);
CREATE TABLE typeA(
typeA_id SERIAL PRIMARY KEY
);
CREATE TABLE typeB(
typeB_id SERIAL PRIMARY KEY
);
CREATE TABLE typeC(
typeC_id SERIAL PRIMARY KEY
);
--
Kevin McCarthy
kemccarthy1@gmail.com
В списке pgsql-novice по дате отправления
От: Tom Lane
Дата:
От: Jasbinder Singh Bali
Дата: