Changing an identity column from INT
to BIGINT
in a table of this size is a significant operation that requires careful planning to minimize impact on performance and resources. Given your constraints, here are the best approaches and considerations:
Approach 1: Drop and Recreate the Clustered Index
- Drop the Clustered Index – This will require exclusive access to the table and could be resource-intensive.
- Alter the Column to 'BIGINT' – Once the index is dropped, changing the column type should be relatively straightforward.
- Recreate the Clustered Index – Since the rows are already ordered, this step might not be as expensive as a full rebuild.
However, be prepared for substantial log file usage.
Pros: Simpler process, avoids full data movement.
Cons: Dropping a clustered index will lock the table and could lead to downtime
Approach 2: Create a New Table
- Create a new table with
BIGINT
for col3. - Create the clustered index on the new table.
- Insert the data from the original table into the new one (
INSERT INTO new_table SELECT * FROM original_table
). - Recreate the non-clustered indexes.
- Rename the tables (or swap them).
Pros: Allows for minimal locking and can be done in stages.
Cons: High system resource usage (especially for tempdb
and transaction logs), requires space for a new table
Estimated Time
Exact timing depends on factors like disk speed, server load, and available resources. A full table copy (Approach 2) will take significantly longer than simply altering the column after dropping the index (Approach 1).
Recommendation
If downtime is acceptable, Approach 1 (drop index, alter column, recreate index) is simpler and cleaner. If availability and minimal locking are priorities, Approach 2 (creating a new table) offers more control at the cost of complexity.