开发者

How to change a normal column to "computed" column

开发者 https://www.devze.com 2023-03-22 06:06 出处:网络
I ha开发者_运维技巧ve 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 ?Preserve the old data:

I ha开发者_运维技巧ve 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 ?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号