From: | Gregory Brauer <greg(at)wildbrain(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Altering live databases |
Date: | 2002-08-07 21:45:49 |
Message-ID: | 3D51950D.7090004@wildbrain.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I am starting to do a test run of maintaining a live database,
and I'm trying to figure out how to add a relation to an existing
table. Lets say I do:
CREATE TABLE something
(
id serial ,
);
And later I decide I *really* wish I had done:
CREATE TABLE something
(
id serial ,
foo_id int4 not null,
foreign key(foo_id) references foo(id) on update CASCADE,
);
How can I update a live database to add the missing relation?
So far I know that I need to:
ALTER TABLE issue_transaction ADD COLUMN foo_id int4 not null;
But how do I declare the foreign key and how do I declare the
ON UPDATE? Is this something that is better done from a
backup? I've noticed the trigger syntax in a backup isn't
exactly friendly, and the TOC Entry IDs are numbered, but I
woudn't know what number to use to create a new one.
Advice?
Greg
From | Date | Subject | |
---|---|---|---|
Next Message | Christopher Kings-Lynne | 2002-08-08 02:32:51 | Re: ALTER TABLE follow up |
Previous Message | Ross J. Reedstrom | 2002-08-07 18:54:09 | Re: running psql in a cron job |