re: REFERENCES

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

re: REFERENCES

От:
"ngterry" <ngterry@sinaman.com>
Дата:

Hi!

I am just a newbie in postgresql.  What if:

CREATE TABLE purchase (id int, po int, date date, PRIMARY KEY (id));

CREATE TABLE lcopen (lc numeric, po int, PRIMARY KEY (lc)); 

CREATE TABLE lcreceive (id int, lc numeric REFERENCES lcopen, purid int REFERENCES purchase);

How do I refer the keywords po in table lcopen to table purchase the po keywords?  I am quite confuse, since I have announce id in table purchase as PRIMARY KEY.  I do not know how to key another keywords.

Best regards,

Terence
==================================================================
新浪SMS短訊:http://sms.sina.com.hk
給遠方親友傳上無限驚喜
50MB 電子郵件 :http://sinamail.sina.com.hk



Re: re: REFERENCES

От:
Darren Ferguson <darren@crystalballinc.com>
Дата:
CREATE TABLE purchase (id int, po int, date date, PRIMARY KEY (id));

CREATE TABLE lcopen (lc numeric, po int, PRIMARY KEY (lc));

CREATE TABLE lcreceive (
   id int, 
   lc numeric REFERENCES lcopen(lc),
   purid int REFERENCES purchase(id)
)
;

I think this is what you are asking this will effectively make lc and
purid in lcreceive foreign keys of the other tables

Darren Ferguson

On Sun, 10 Mar 2002, [big5] ngterry wrote:

> 
> Hi!
> 
> I am just a newbie in postgresql.  What if:
> 
> CREATE TABLE purchase (id int, po int, date date, PRIMARY KEY (id));
> 
> CREATE TABLE lcopen (lc numeric, po int, PRIMARY KEY (lc)); 
> 
> CREATE TABLE lcreceive (id int, lc numeric REFERENCES lcopen, purid int REFERENCES purchase);
> 
> How do I refer the keywords po in table lcopen to table purchase the po keywords?  I am quite confuse, since I have announce id in table purchase as PRIMARY KEY.  I do not know how to key another keywords.
> 
> Best regards,
> 
> Terence
> ==================================================================
> �s��SMS�u�T�Ghttp://sms.sina.com.hk
> �������ˤͶǤW�L������
> 50MB �q�l�l�� �Ghttp://sinamail.sina.com.hk
> 
> 
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
> 

FAQ