I have a table in MSSQL server 2008. I would like to change one of the column in that table to computed column. Could somebody tell me how do I do that ?
Asked
Active
Viewed 1.0k times
1 Answers
30
Preserve the old data:
EXEC sp_rename 'MyTable.OldCol', 'RenamedOldCol', 'COLUMN';
Add computed column
ALTER TABLE MyTable ADD ComputedCol AS (some expression);
Then, when you're happy
ALTER TABLE MyTable DROP COLUMN RenamedOldCol;

gbn
- 422,506
- 82
- 585
- 676