Re: Use of reference table ('look-up-table') and FK constraint

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: Use of reference table ('look-up-table') and FK constraint
Дата
Msg-id 200210151027.51235.josh@agliodbs.com
обсуждение исходный текст
Ответ на Use of reference table ('look-up-table') and FK constraint  (Charles Hauser <chauser@duke.edu>)
Ответы Re: Use of reference table ('look-up-table') and FK constraint  (Charles Hauser <chauser@duke.edu>)
Список pgsql-sql
Charles,

CREATE TABLE phone_types (type VARCHAR(10) NOT NULL PRIMARY KEY
);

INSERT INTO phone_types
VALUE ( 'Work' );
INSERT INTO phone_types
VALUE ( 'Home' );
etc ...

CREATE TABLE phone (        phone_id             Identifier_type IDENTITY,        phone_number         varchar(20) NOT
NULL,       community_id         numeric(12) NOT NULL,        type                 varchar(10) NULL REFERENCES
phone_types(type)ON  
DELETE SET NULL );

Simple, neh?   And it lets you add new types, at any time, without re-building
the table.   IMHO, the guy who built the database you're converting was
either a total hack or working around some serious platform shortcomings.

BTW, are you sure you want phone.type to be NULLable?   Were it me, I would
make it required, in which case the declaration would be:
        type                 varchar(10) NOT NULL REFERENCES
phone_types(type)

--
-Josh BerkusAglio Database SolutionsSan Francisco



В списке pgsql-sql по дате отправления:

Предыдущее
От: Stephan Szabo
Дата:
Сообщение: Re: Use of reference table ('look-up-table') and FK constraint
Следующее
От: Vincent Stoessel
Дата:
Сообщение: Quick contraint question