Обсуждение: Why can't I create two tables that are foreign keys for each other?

Поиск
Список
Период
Сортировка

Why can't I create two tables that are foreign keys for each other?

От
Eric Du
Дата:
Here is my sql script to create two tables that are foreign keys for
each other.

BEGIN;
CREATE TABLE t1 (
    id serial PRIMARY KEY,
    t2_id integer REFERENCES t2 INITIALLY DEFERRED
);
CREATE TABLE t2 (
    id serial PRIMARY KEY,
    t1_id integer REFERENCES t1 INITIALLY DEFERRED
);
END;

psql complains the following:
    ERROR:  Relation 't2' does not exist
    ERROR:  Relation 't1' does not exist

What's the matter?

Thanks in advance,

--
Eric Du
-----------------------------------
Tel: (86-010) 64181818-821
Fax: (86-010) 64181385
Leyou WebSite: http://www.leyou.com