加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

SQL – 如何在计算列上ALTER COLUMN

发布时间:2020-12-12 16:55:17 所属栏目:MsSql教程 来源:网络整理
导读:我正在使用SQL Server 2008.可以更改计算列而不实际删除列,然后再次添加(我可以上班)?例如,我有这个表: CREATE TABLE [dbo].[Prices]([Price] [numeric](8,3) NOT NULL,[AdjPrice] AS [Price] / [AdjFactor],[AdjFactor] [numeric](8,3) NOT NULL) 后来意识
我正在使用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读