pg.ddx.io pgsql-admin@postgresql.org mailing list archivehelp / color / mirror / Atom feed
From: Karen Goh <karenworld@yahoo.com>
To: pgsql-admin@lists.postgresql.org
Subject: 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 00:58:05 +0000 (UTC)
Message-ID: <820008379.2579287.1563670685484@mail.yahoo.com> (raw)
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.
view thread (26+ messages) latest in thread
Message-ID: <820008379.2579287.1563670685484@mail.yahoo.com> Permalink: ../820008379.2579287.1563670685484@mail.yahoo.com/ Also on: postgresql.org/message-id/820008379.2579287.1563670685484@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-admin@postgresql.org Cc: karenworld@yahoo.com, pgsql-admin@lists.postgresql.org 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: <820008379.2579287.1563670685484@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 DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox