Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E5CBB475B07 for ; Fri, 3 Jan 2003 08:56:04 -0500 (EST) Received: from server45.aip.com.br (unknown [200.199.192.5]) by postgresql.org (Postfix) with ESMTP id 69434474E61 for ; Fri, 3 Jan 2003 08:56:02 -0500 (EST) Received: from PEDRO ([10.1.0.11]) by server45.aip.com.br with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id CFPJ9QQL; Fri, 3 Jan 2003 11:57:40 -0300 Message-ID: <000d01c2b32e$8529eca0$0b00010a@aip.com.br> From: "Pedro Igor" To: Subject: Query Date: Fri, 3 Jan 2003 11:46:27 -0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000A_01C2B31D.C00F3200" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/23 X-Sequence-Number: 10888 This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C2B31D.C00F3200 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Regards ..... I hope someone can help me in this query. Have a field in a table that needs to check if another table has the valu= e that is being inserted. Ex: table A=20 - id int constraint pkey_id primary key, =20=20=20=20 =20=20=20=20 table B - id int constraint fkey_A_B references A, Here comes my doubt: table C - id int constraint fkey_A_C references A check (if exists B.id =3D C= .id) How can i build this expression so, when I insert a tupple in table C t= he field will check in the table A(ok, because is a foreign key) and also i= n table B .... I have tried : check (select count(b.id) from B b where b.id =3D id) <>= 0) .... but doesn=B4t work ......=20 I can use trigger here, but i don=B4t know if is the best solution ..... =20=20=20=20=20 Thanks, Pedro Igor =20=20=20 ------=_NextPart_000_000A_01C2B31D.C00F3200 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Regards .....
 
  I hope someone can help me in this= =20 query.
  Have a field in a table that n= eeds to=20 check if another table has the value that is being inserted.
  Ex:
    table A
      - id int co= nstraint=20 pkey_id primary key,
    
   
    table B
      - id int co= nstraint=20 fkey_A_B references A,
 
    Here comes my=20 doubt:
 
    table C
      - id int co= nstraint=20 fkey_A_C references A check (if exists B.id =3D C.id)
 
    How can i build this ex= pression=20 so, when I insert a tupple in table C the field will check in the table A(o= k,=20 because is a foreign key) and also in table B ....
    I have tried : check (s= elect=20 count(b.id) from B b where b.id =3D id) <> 0) .... but doesn=B4t= work=20 ......
    I can use trigger here,= but i=20 don=B4t know if is the best solution .....
     
   Thanks,
 
        Pedr= o=20 Igor
  
------=_NextPart_000_000A_01C2B31D.C00F3200--