Hi
I have a table that currently has 466 columns and about 700,000
records. Adding a new DEFAULT column to this table takes a long time.
It it a lot faster to recreate the table with the new columns and then
copy all of the data across.
As far as I am aware when you add a DEFAULT column the following
happens:
a) The column is added with a NULL property
b) Each row is updated to be set to the DEFAULT value
c) The column is changed to NOT NULL.
However, adding the column as NOT NULL with the DEFAULT seems to take a
lot longer than if I do steps a) - c) separately.
When I say a long time, adding just a single DEFAULT column takes
around 6 hours. Surely it should not take this long?
There is a trigger on this table but disabling this does not seem to
make much difference.
Can anybody give me any advice on the use of DEFAULT columns please?
When should they be used, benefits, disadvantages, alternatives etc.
Also should it really take as long as it is taking or is there a
problem with my setup?
If I am honest I can't see why DEFAULT columns should be used as the
values could always be inserted explicitly via the application
Thanks in Advance.
Paul
I have a table that currently has 466 columns and about 700,000
records. Adding a new DEFAULT column to this table takes a long time.
It it a lot faster to recreate the table with the new columns and then
copy all of the data across.
As far as I am aware when you add a DEFAULT column the following
happens:
a) The column is added with a NULL property
b) Each row is updated to be set to the DEFAULT value
c) The column is changed to NOT NULL.
However, adding the column as NOT NULL with the DEFAULT seems to take a
lot longer than if I do steps a) - c) separately.
When I say a long time, adding just a single DEFAULT column takes
around 6 hours. Surely it should not take this long?
There is a trigger on this table but disabling this does not seem to
make much difference.
Can anybody give me any advice on the use of DEFAULT columns please?
When should they be used, benefits, disadvantages, alternatives etc.
Also should it really take as long as it is taking or is there a
problem with my setup?
If I am honest I can't see why DEFAULT columns should be used as the
values could always be inserted explicitly via the application
Thanks in Advance.
Paul
Comment