Re: An easy question about creating a primary key

Поиск
Список
Период
Сортировка
От Josh Berkus
Тема Re: An easy question about creating a primary key
Дата
Msg-id web-519076@davinci.ethosmedia.com
обсуждение исходный текст
Ответ на An easy question about creating a primary key  ("Ligia Pimentel" <lmpimentel@yahoo.com>)
Список pgsql-sql
Ligia,

> I want to create a primary key constraint on an existing table. The
> documentation says I can't . Please confirm. If this is true... How
> can I
> rename the existing table so I can create the new one and copy the
> data?

FYI, this question is more appropriate for the NOVICE list.

You would use the same method that you use to drop and recreate the
table for other reasons:

CREATE TABLE tablea_temp AS
SELECT * FROM tablea;

DROP tablea;

CREATE tablea (  primary_key SERIAL ...  <snip>
);

INSERT INTO tablea (column list)
SELECT (column list) FROM tablea_temp;

And don't forget to re-build your indexes!

-Josh Berkus




______AGLIO DATABASE SOLUTIONS___________________________                                      Josh Berkus Complete
informationtechnology      josh@agliodbs.com  and data management solutions       (415) 565-7293 for law firms, small
businesses       fax 621-2533   and non-profit organizations.      San Francisco
 


В списке pgsql-sql по дате отправления:

Предыдущее
От: "Josh Berkus"
Дата:
Сообщение: Re: Need help with a college SQL exam question...
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Error in executing plpgsql function