2012-08-08 84 views
0

我写的部署脚本错误插入或使用被在“查询/运行时间”

  1. 创建一个新列的默认值为0,是空值创建了一列更新数据能够
  2. UPDATE当某条件满足

还要注意的是,如果我明确设置的默认值0在INSERT语句我收到的时候我正在更新数据 -

同样的错误列数据

错误消息 -

无效的列名'isConvertWithDivison'。

SQL我使用 -

ALTER TABLE dbo.accountCurrencies 
    ADD isConvertWithDivison BIT NULL DEFAULT 0 

UPDATE dbo.accountCurrencies SET isConvertWithDivison = 1 WHERE currencyName = 'USD' 

INSERT dbo.accountCurrencies 
     (currencyName) 
VALUES ('AUD'),('DKK'),('RUB'),('SEK') 

似乎很明显是怎么回事,但我要如何解决此问题?

我已经尝试过在执行数据更改之前让新的collumn提交到数据库,但仍然没有运气。

BEGIN TRANSACTION 
    ALTER TABLE dbo.accountCurrencies 
     ADD isConvertWithDivison BIT NULL DEFAULT 0 
COMMIT TRANSACTION 

UPDATE dbo.accountCurrencies SET isConvertWithDivison = 1 WHERE currencyName = 'USD' 

INSERT dbo.accountCurrencies 
     (currencyName) 
VALUES ('AUD'),('DKK'),('RUB'),('SEK') 

仅供参考 - 运行SQL 2008 R2

回答

1

使用GO ALTER语句之后,

ALTER TABLE dbo.accountCurrencies 
    ADD isConvertWithDivison BIT NULL DEFAULT 0 

go 

UPDATE dbo.accountCurrencies SET isConvertWithDivison = 1 WHERE currencyName = 'USD' 

go 
INSERT dbo.accountCurrencies 
     (currencyName) 
VALUES ('AUD'),('DKK'),('RUB'),('SEK') 
+0

谢谢乔摹瑟 – SimonGates 2012-08-08 11:53:11