Re: ALTER TABLE and adding FK Constraints - Assistance Requested

From: ries van Twisk <pg(at)rvt(dot)dds(dot)nl>
To: Michael Black <michaelblack75052(at)hotmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: ALTER TABLE and adding FK Constraints - Assistance Requested
Date: 2009-03-29 15:12:12
Message-ID: ED7B1B1E-867D-4245-A55F-4C09AADEEC62@rvt.dds.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Mar 29, 2009, at 10:04 AM, Michael Black wrote:

> First, I am relatively new to postgres, but have been using database
> (design not administering) for about 20 years (you would think that
> I could figure this out - lol). At an rate, I am trying to create
> tables that have forgein keys via a script. What happens is if the
> table that is referred to in the forgeing key does not exist, the
> table fails to create. Undertandable. So what I need to do is
> create all the tables and then go back and alter the tables by
> adding the forgein key constraint. I got that. But what I am
> looking for is the correct syntax to add the forgein key constrant.
> I have tried "ALTER TABLE <name> CONSTRANT <constraint description>"
> and "ALTER TABLE <name> ADD CONSTRANT <constraint description>".
> But both fail.
>
> Yes I am being lazy. I should go through the script and create the
> tables that are referenced first then the ones with the forgein
> key. But I also need to know this in the even the schema changes in
> the future and more constratins are necessary. I have looked at the
> ALTER TABLE syntax on postgres but it refers back to the CREATE
> TABLE function.
>
> Michael
>

Michael,

you are looking for this : http://www.postgresql.org/docs/current/static/sql-altertable.html

Ries

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Black 2009-03-29 15:26:26 Re: ALTER TABLE and adding FK Constraints - Assistance No longer needed
Previous Message Michael Black 2009-03-29 15:04:28 ALTER TABLE and adding FK Constraints - Assistance Requested