Reputation: 24364
We have a column char(16)
which needs to be as long as char(128)
. How to change the datatype in SQL Server 2008 R2 if the table contains over 100 000 rows? It maybe doesn't matter though.
How expensive is this operation?
Upvotes: 0
Views: 90
Reputation: 21766
Assuming your table name is YourTable
ALTER TABLE YourTable ALTER COLUMN YourCharColumn CHAR(128)
or in case some difficulties
ALTER TABLE YourTable ADD NewChar char(128) NOT NULL CONSTRAINT df DEFAULT OldChar
GO
ALTER TABLE YourTable DROP CONSTRAINT df
GO
ALTER TABLE YourTable DROP COLUMN OldChar
GO
exec sp_rename('YourTable.NewChar', 'OldChar', 'COLUMN')
Upvotes: 3