Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hp0C3-0006Ru-6y for pgsql-admin@arkaria.postgresql.org; Sun, 21 Jul 2019 00:59:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hp0B2-0008D6-7e for pgsql-admin@arkaria.postgresql.org; Sun, 21 Jul 2019 00:58:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hp0B1-0008Cz-AT for pgsql-admin@lists.postgresql.org; Sun, 21 Jul 2019 00:58:11 +0000 Received: from sonic309-15.consmr.mail.bf2.yahoo.com ([74.6.129.125]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hp0Ay-0005OP-H2 for pgsql-admin@lists.postgresql.org; Sun, 21 Jul 2019 00:58:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1563670685; bh=WPdKVd7Q15aGRvkRfEKZjMEj92qiJQMiV9gpqSGS6iM=; h=Date:From:To:Subject:From:Subject; b=hMbS8nfhLwTnZHgUrv/Fb64rS6BMuHizw5V50D4D3qIuCxjtwSAyq2KnxqTCP72SDId4oyeJzseUjh5RmE0HnOujogOctWtrfG70LeMROqNvFpzg/HS1VOh2XEOhJ6c6CqdZr4FDke9pBdQqWEQAobFKbOrKshBeESsMpA6FSXhdxmTmeBfQ8peUusrRz43BsvF7raTCLvV5xns6KI3VCUZTikaDK5BV0S45+gda7ywjNPUM8IcCSCDh53VxdqO+O+0S/t3MZ4Il/xaH4aNtvu93BJ4lCYlm9VEoZT/pPOIgRJp5VQ9KZzO/gI3x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R.1hE6TG7LoeYxOY n6EvJ93q37QxJCMUSASIctByL5IG6_yPfwV3XbELhLJPiRfALFlZj4PEao9JdUd8NF6jYRAyYaYd .7szp5koXkk0nchFUryTZJJspVt.KclOQR_SHGXGOFVVzpUfWihFYmbzzom3k85FgHgX8b2JXO0D EpYQCm2.5Om_LQCzKLoLLj3DFjrMYF7jsThPLuR_KkKgS78A8CRoDwgcomQmQ.QZuFnfU Received: from sonic.gate.mail.ne1.yahoo.com by sonic309.consmr.mail.bf2.yahoo.com with HTTP; Sun, 21 Jul 2019 00:58:05 +0000 Date: Sun, 21 Jul 2019 00:58:05 +0000 (UTC) From: Karen Goh To: pgsql-admin@lists.postgresql.org Message-ID: <820008379.2579287.1563670685484@mail.yahoo.com> Subject: How do I alter an existing column and add a foreign key which is a Primary key to a table? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Length: 695 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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.