SQL – 如何在计算列上ALTER COLUMN

我正在使用sql Server 2008.可以更改计算列而不实际删除列,然后再次添加(我可以上班)?例如,我有这个表:
CREATE TABLE [dbo].[Prices](
[Price] [numeric](8,3) NOT NULL,[AdjPrice] AS [Price] / [AdjFactor],[AdjFactor] [numeric](8,3) NOT NULL)

后来意识到我有一个错误的潜在差距,我想改变[Adjprice]列来处理这个,但如果我只是删除列并再次添加,我失去了列顺序.

我想做一些像:

ALTER TABLE dbo.[Prices]
ALTER COLUMN [AdjPrice] AS (CASE WHEN [AdjFactor] = 0 THEN 0 ELSE [Price] / [AdjFactor] END)

但这是不正确的.如果这是可能的话,还是有另外一个解决方案,我会很乐意帮忙.

解决方法

不幸的是,您不能首先删除列.

From MSDN

ALTER COLUMN
Specifies that the named column is to be changed or altered. ALTER COLUMN is not allowed if the compatibility level is 65 or lower. For more information,see sp_dbcmptlevel (Transact-sql).

  • The modified column cannot be any one of the following:

    • A computed column or used in a computed column.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...