2011-04-07 261 views
1

我試圖創建一個非常簡單的觸發器,並且得到錯誤: Msg 8197,Level 16,State 4,Procedure trig_UpdateTransferBools,Line 1 對象'dbo.DW_WEEK_RANGE'不存在或無效爲此操作。創建觸發器

該表格明顯存在;我創造了它! 這可能是一個權限問題呢?

CREATE TRIGGER dbo.trig_UpdateTransferBools ON [dbo.DW_WEEK_RANGE] 
AFTER INSERT, UPDATE 
AS 
BEGIN 

    IF (SELECT Transfer FROM dbo.DW_WEEK_RANGE WHERE Module = 'PURCHASES') = 1 
     BEGIN 
      UPDATE [dbo.DW_WEEK_RANGE] SET Transfer = 0 WHERE Module = 'SALES' 
      UPDATE [dbo.DW_WEEK_RANGE] SET Transfer = 0 WHERE Module = 'RETAIL SALES' 
     END 

END 
+0

你確定它是在dbo上下文中創建的嗎?我們可以看到你的數據庫的截圖嗎? – 2011-04-07 13:52:01

回答

1

它必須是dbo.[DW_WEEK_RANGE][dbo].[DW_WEEK_RANGE][dbo.DW_WEEK_RANGE]

schema.table

你也可以省略括號,括號內是有這樣您就可以名錶一些愚蠢像一個空白空間或關鍵字

例如

CREATE TABLE [ ](id INT) 

INSERT [ ] VALUES(1) 

SELECT * FROM [ ] 
+0

+1:接我42秒。 – 2011-04-07 13:53:50

+0

那麼你知道一切的答案是42 :-) – SQLMenace 2011-04-07 13:59:24