Changing an int column to a varchar column

/ Published in: SQL
Save to your folder(s)

Copy this code and paste it in your HTML
  1. EXEC sp_rename 'TableName.ColumnName', 'ColumnName_int', 'COLUMN';
  2. GO
  3. ALTER TABLE 'TableName' ADD COLUMN ColumnName VARCHAR(10);
  4. GO
  5. UPDATE TABLE 'TableName' SET ColumnName = CAST(@ColumnName_int AS VARCHAR(10));
  6. GO
  7. ALTER TABLE 'TableName' DROP COLUMN ColumnName;
  8. GO

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.