Subject Re: [firebird-support] Creating / Altering Primary Keys on production tables
Author Helen Borrie
At 07:14 PM 31/10/2003 +0530, you wrote:

>Hi Everyone,
>
>This may have been answered earlier ... but I seem to have some trouble
>accessing the archive ... so here goes
>
>I have a few tables created with no primary key defined. I now want to
>add a primary key to the specified tables. No change in datatypes or
>anything ... just adding simple primary keys to a few tables. How can I
>do it ?

alter table atable
add constraint pk_atable primary key(pk_id);

>Do I need to make the users log out completely ?

Yes

>What
>precautions need to be taken apart from ensuring that the column
>definition is unique & not null.

None


>Also if a table has an existing primary key can I drop that to create a
>new primary key. The column which is to now become the primary key has
>no null values and values are unique but the constraints have not been
>put while defining the columns. Again what are the precautions.

Backup.

then
alter table atable
drop constraint rdb$primarynn <--- make sure you get the right one
commit;
alter table atable
add constraint........

>I remember some talk about system tables and changing them in another
>thread somewhere. Would prefer not to touch those coz I do not
>understand much about how they work anyways :-)

Wise man. I do understand how they work but I don't touch 'em.

>I am using FB 1.0.2 - Are there any differences while using the older
>versions.

Fewer bugs. More bugs than FB 1.0.3. :-)

h.