Adding a Primary Key to an exisiting table
Adding a Primary Key to an exisiting table
От:
Maly Kaing <mkaing1@gl.umbc.edu>
Дата:
Hi I just exported my MS Access databases into postgres using an ODBC driver, but the thing is during the export postgres doesn't recognize any of my primary keys in Access. Is there any way to alter the tables so that i can make one of my current fields the primary key? I don't want to drop the column since I already have data in the table and i don't want to create/drop tables as some of the documentation suggests since most of my tables have 10+ fields.. any suggestions?? mtk
Re: Adding a Primary Key to an exisiting table
От:
Bhuvan A <bhuvansql@myrealbox.com>
Дата:
> Hi > > I just exported my MS Access databases into postgres using an ODBC driver, > but the thing is during the export postgres doesn't recognize any of my > primary keys in Access. > Is there any way to alter the tables so that i can make one of my current > fields the primary key? I don't want to drop the column since I already > have data in the table and i don't want to create/drop tables as some of > the documentation suggests since most of my tables have 10+ fields.. any > suggestions?? > AFAIK, it can be done in any of the below two ways: 1. Create unique index CREATE UNIQUE INDEX index_name ON table_name USING btree (field1, .., fieldn); 2. Add primary key constraint ALTER TABLE table_name ADD PRIMARY KEY (field1, .., fieldn); For this to happen, the fields should have unique values. regards, bhuvaneswaran