agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Karen Goh <karenworld@yahoo.com>
To: pgsql-admin@lists.postgresql.org, Ron <ronljohnsonjr@gmail.com>
Subject: Re: How do I alter an existing column and add a foreign key which is a Primary key to a table?
Date: Sun, 21 Jul 2019 14:24:35 +0000 (UTC)
Message-ID: <1745586001.2633224.1563719075867@mail.yahoo.com> (raw)
In-Reply-To: <923fb3b1-90e9-e0b5-bc5b-d896128c3f28@gmail.com>
References: <820008379.2579287.1563670685484@mail.yahoo.com>
	<5CE41E80-274A-44DA-9553-E2DCA260F751@jakobs.com>
	<385857992.2643116.1563717238725@mail.yahoo.com>
	<923fb3b1-90e9-e0b5-bc5b-d896128c3f28@gmail.com>

 




On Sunday, July 21, 2019, 10:12:33 PM GMT+8, Ron <ronljohnsonjr@gmail.com> wrote:


On 7/21/19 8:53 AM, Karen Goh wrote:
>
> On Sunday, July 21, 2019, 3:28:10 PM GMT+8, Holger Jakobs
> <holger@jakobs.com> wrote:
>
> Am 21. Juli 2019 02:58:05 MESZ schrieb Karen Goh <karenworld@yahoo.com>:
>
[snip]

>
> This looks like a 1:1 relationship which is to be avoided.
>
> One ALTER TABLE command either adds a primary or a foreign key. There is
> no FK without the keyword REFERENCES.
>
> FK relationships help in keeping the data consistent, but they are totally
> unrelated to/useless for SELECT statements and their JOIN operations. This
> is a common misconception.
>
> Hi Holger,
>
> After reading your reply, I am confused now.
>
> Cos without creating foreign key in my tutor_subject how am I going to
> retrieve the zipcode at s_tutor table that meet the list of subject_name
> and tutor_id in tutor_subject ? There should have some reference right ?
> If not, how does the database tell this zipcode belong to which tutor_id ?


The reference is in the SELECT statement, not in the FK definition.

SELECT s_tutor.zip_code
from subject_tutor, s_tutor
where s_tutor.tutor_id = subject_tutor.tutor_id
and subject_tutor.subject_name = 'Angela Merkel';

Hi Ron,

You can't Select s_tutor.zip_code from subject_tutor as zip_code belongs to s_tutor table.

Hence, I wrote my last message about my confusion.



-- 
Angular momentum makes the world go 'round.



  

view thread (26+ messages)  latest in thread

Message-ID: <1745586001.2633224.1563719075867@mail.yahoo.com>
Permalink:  ../1745586001.2633224.1563719075867@mail.yahoo.com/
Also on:    postgresql.org/message-id/1745586001.2633224.1563719075867@mail.yahoo.com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: karenworld@yahoo.com, ronljohnsonjr@gmail.com
  Subject: Re: How do I alter an existing column and add a foreign key which is a Primary key to a table?
  In-Reply-To: <1745586001.2633224.1563719075867@mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox