Creating Trigger
I'm trying to create a very simple trigger and am getting the error: Msg 8197, Level 16, State 4, Procedure trig_UpdateTransferBools, Line 1 The object 'dbo.DW_WEEK_RANGE' does not exist or is invalid for this operation.
The table clearly exists; I created it! Could this be a permissions issue at all?
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 SALE开发者_运维技巧S'
END
END
It has to be dbo.[DW_WEEK_RANGE]
or [dbo].[DW_WEEK_RANGE]
not [dbo.DW_WEEK_RANGE]
schema.table
you can also leave out the brackets, the brackets are there so that you can name tables something silly like a blank space or a keyword
example
CREATE TABLE [ ](id INT)
INSERT [ ] VALUES(1)
SELECT * FROM [ ]
精彩评论