From: | Carol Walter <walterc(at)indiana(dot)edu> |
---|---|
To: | |
Cc: | pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Primary key on existing table? |
Date: | 2009-08-26 18:23:56 |
Message-ID: | 6F988D72-9A51-4613-8BEA-AD112CDCA1D1@indiana.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
Thanks, guys. Worked like a charm.
Carol
On Aug 25, 2009, at 6:25 PM, Scott Marlowe wrote:
> On Tue, Aug 25, 2009 at 2:25 PM, Carol Walter<walterc(at)indiana(dot)edu>
> wrote:
>> This may be a silly question but I don't see any place where the
>> documentation explicitly addresses whether or not you can designate a
>> particular column as a primary key after the table is created. I
>> used the
>> "create table as " syntax to create a table with the same columns
>> as an
>> original table, but I want to rename id column, make it a serial, and
>> designate it as a primary key. Is it possible to do this? I've
>> tried a
>> number of things to do this and none of them have worked.
>
> This is an alter. Look up alter table, and look for constraints.
> Standard format would look like this:
>
> create table xyz (i int, t text);
> ALTER TABLE / ADD PRIMARY KEY will create implicit index "xyz_pk" for
> table "xyz"
> ALTER TABLE
> smarlowe=> \d xyz
> Table "public.xyz"
> Column | Type | Modifiers
> --------+---------+-----------
> i | integer | not null
> t | text |
> Indexes:
> "xyz_pk" PRIMARY KEY, btree (i)
>
> --
> Sent via pgsql-admin mailing list (pgsql-admin(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-admin
From | Date | Subject | |
---|---|---|---|
Next Message | Jan-Peter Seifert | 2009-08-26 19:32:03 | Re: Trouble with postgres user's password on Windows |
Previous Message | Andy Shellam | 2009-08-26 16:51:51 | Re: Avoid duplicated rows when restoring data from pg_dumpall ?? |