From: | Karen Goh <karenworld(at)yahoo(dot)com> |
---|---|
To: | pgsql-admin(at)lists(dot)postgresql(dot)org |
Subject: | How do I alter an existing column and add a foreign key which is a Primary key to a table? |
Date: | 2019-07-21 00:58:05 |
Message-ID: | 820008379.2579287.1563670685484@mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin pgsql-sql |
Hi all,
I used to write a script in MYSQL and foreign and primary key will be created.
With PG4Admin, I am lost.
I realised now that the keys are not created and perhaps that is why the join query is not working out.
Please let me know what is the correct way to alter a column in a table to have foreign key to a tutor_id which is also the primary key of that table.
So, meaning I need to create a foreign key as well as primary key for tutor_id.
So far, this is what I have attempted but it is not working.
ALTER TABLE tutor_subject
ADD CONSTRAINT tutor_subject_pk
PRIMARY KEY (tutor_id)
ADD CONSTRAINT tutor_subject_fk
FOREIGN KEY (tutor_id)
Please help me on this.
Thanks.
From | Date | Subject | |
---|---|---|---|
Next Message | Ron | 2019-07-21 01:25:33 | Re: How do I alter an existing column and add a foreign key which is a Primary key to a table? |
Previous Message | jmz | 2019-07-20 22:24:58 | Fwd: Database.Schema.Table |
From | Date | Subject | |
---|---|---|---|
Next Message | Ron | 2019-07-21 01:25:33 | Re: How do I alter an existing column and add a foreign key which is a Primary key to a table? |
Previous Message | Alexandru Lazarev | 2019-07-19 19:52:05 | Re: pg_advisory_lock lock FAILURE / What does those numbers mean (process 240828 waits for ExclusiveLock on advisory lock [1167570,16820923,3422556162,1];)? |