When asked to change a column width on a very large table , such as 30 million rows and disk storage of 30 GB , these are some of the steps I take.
USE [MyDB]
GO
/****** Resize Table [dbo.MyReports].HolderName to varchar 64 from varchar 50***/
Alter TABLE MyReports
Alter column [HolderName] [varchar](64))
On a small table – this might be OK to execute and barely any activity will appear. But if attempting to execute on a large table on a busy Production Server – then some tactics are required.
Some possible tactics:
1)Execute the code as a SQL server Agent task – this will allow the code ,to run as a background task and scheduled for convenience
2)Set the recovery model to Simple , but as this is a single transaction some logging will take place.
3)Backup , before and after.Use the COPY_ONLY option BACKUP to avoid breaking the backup chain
4)If downtime is acceptable : use BCP to export data , TRUNCATE the table , alter column size, use BCP to import data. Keep logging turned off
Deciding on which tactic to apply will depend on a number of factors , including disk storage availability, downtime , how much you can isolate the database
Ref:Jack Vamvas (http://www.sqlserver-dba.com)
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |