Subject | Re: Adding a Primary Key |
---|---|
Author | Adam |
Post date | 2006-04-07T23:55:42Z |
--- In firebird-support@yahoogroups.com, Jon Aldrich <jonald21@...> wrote:
or do you mean you are creating a new field to be that you want to use
as the primary key?
If you are elevating an existing 'candidate key' field(s):
Creating the primary key constraint automatically creates the index
and populates it with the existing data.
If you are creating a new field to be used as the primary key on a
table with data already in it:
It is very important to note that you can not do this as an atomic
operation. You must create a backup before-hand.
1. Add the new field and define the constraint.
2. Commit
3. Populate the new field, making sure every record in the table has a
PK record
4. Commit
5. Backup and perform a test restore
Until step 4, the new field contains NULLs, and as a primary key field
this would cause subsequent backups to fail to restore. You have been
warned.
You do not need to do anything other than define the constraint though
for the index to be active.
Adam
>not
> If I use ALTER TABLE to ADD a primary key too an existing table (with
> data), is the index just created or is created and filled? If it's
> filled how do I "reindex" ?Do you mean that you are elevating a given field to primary key status
or do you mean you are creating a new field to be that you want to use
as the primary key?
If you are elevating an existing 'candidate key' field(s):
Creating the primary key constraint automatically creates the index
and populates it with the existing data.
If you are creating a new field to be used as the primary key on a
table with data already in it:
It is very important to note that you can not do this as an atomic
operation. You must create a backup before-hand.
1. Add the new field and define the constraint.
2. Commit
3. Populate the new field, making sure every record in the table has a
PK record
4. Commit
5. Backup and perform a test restore
Until step 4, the new field contains NULLs, and as a primary key field
this would cause subsequent backups to fail to restore. You have been
warned.
You do not need to do anything other than define the constraint though
for the index to be active.
Adam