简体   繁体   English

如何更改列和计算列

[英]How to alter a column and a computed column

In SQL SERVER DB, I need to alter a column baseColumn and a computed column upperBaseColumn . 在SQL SERVER DB中,我需要更改列baseColumn和计算列upperBaseColumn The upperBaseColumn has index on it. upperBaseColumn有索引。

This is how the table looks 这就是表格的外观

create table testTable (baseColumn varchar(10), upperBaseColumn AS (upper(baseColumn))

create index idxUpperBaseColumn ON testTable (upperBaseColumn)

Now I need to increase the column length of both the baseColumn and the upperBaseColumn . 现在我需要增加baseColumnupperBaseColumn的列长度。

What's the best way to do it? 最好的方法是什么?

I suggest you drop the index, then drop the computed column. 我建议你删除索引,然后删除计算列。 Alter the size, then re-add the computed column and the index. 更改大小,然后重新添加计算列和索引。 Using your example.... 用你的例子....

create table testTable (baseColumn varchar(10), upperBaseColumn AS (upper(baseColumn)))
create index idxUpperBaseColumn ON testTable (upperBaseColumn)

Drop Index TestTable.idxUpperBaseColumn

Alter Table testTable Drop Column upperBaseColumn

Alter Table testTable Alter Column baseColumn VarChar(20)

Alter Table testTable Add upperBaseColumn As Upper(BaseColumn)

create index idxUpperBaseColumn ON testTable (upperBaseColumn)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM