Foreign Unique Constraint

Поиск
Список
Период
Сортировка
От Jon Horsman
Тема Foreign Unique Constraint
Дата
Msg-id 4f4c2a010703270621h5137a4e5rb515a9be9034a543@mail.gmail.com
обсуждение исходный текст
Ответы Re: Foreign Unique Constraint  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
Re: Foreign Unique Constraint  (Peter Eisentraut <peter_e@gmx.net>)
Re: Foreign Unique Constraint  (chester c young <chestercyoung@yahoo.com>)
Re: Foreign Unique Constraint  ("Phillip Smith" <phillip.smith@weatherbeeta.com.au>)
Список pgsql-sql
I was wondering if someone could help point me in the right direction
w.r.t. foreign unique constraints.  I'm working on a legacy database
and have a new requirement and am not sure how to do it.

I have something like this

create table table1 (
id SERIAL PRIMARY KEY
extension UNIQUE,
<other fields>
)

create table table2 (
id SERIAL PRIMARY KEY
extension UNIQUE,
<different fields>
)

Basically table 1 and table 2 both have the concept of an extension
that must be unique but the rest of the info in the tables are
different.  I need to ensure that if i add an entry to table 1 with
extension 1000 that it will fail if there is already an entry in
table2 with the same extension.

Essentially i need to do something like the following but i get errors
saying this can't be done.

alter table table1 add check (extension <> table2.extension);

It should be noted i am using pg version 7.4.13 and this can't change.

Thanks for any help you can offer.

Jon.


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

Предыдущее
От: "Claus Guttesen"
Дата:
Сообщение: Re: select vs. select count
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: Foreign Unique Constraint