1) Drop the foreign key Constraints whether this table is being referred as child table.
2) Create a table with existing columns and add not null columns first(including new column)and add null column.
3) Insert the data from existing table to new table created with default value specified for new not null column.
4) In the select statement used HOLDLOCK TABLOCKX.Here HoldLock is used to specify Isolation Level as SERIALIZABLE.and TABLOCKX prevents other users from reading or updating the table
5) Add same foregin keys to the new table
6) Drop the old table
7) Rename new table to old table name using sp_rename
8) Add Clustered and non-clustered Indexes
9) Add foregin keys constraints to child tables which uses this table as primary.
P.S:- Steps 3 to 8 has to be in a single transaction.
No comments:
Post a Comment