我正在嘗試創建一個相當簡單的觸發器,它將一列添加到跟蹤類似於Netflix的電影發行公司的租借數量的列中。SQL Server觸發器:多部分標識符無法綁定
我關注的列是:
- 電影(
movie_id, movie_title, release_year, num_rentals
) - Customer_rentals(
item_rental_id, movie_id, rental_date_out, rental_date_returned
)
我當前觸發看起來是這樣的:
CREATE TRIGGER tr_num_rented_insert
ON customer_rentals FOR INSERT
AS
BEGIN
UPDATE movies
SET num_rentals=num_rentals+1
WHERE customer_rentals.movie_id=movies.movie_id;
END;
它會返回錯誤:
Msg 4104, Level 16, State 1, Procedure tr_num_rented_insert, Line 7
The multi-part identifier "customer_rentals.movie_id" could not be bound.
我只是希望它匹配movie_id的,並添加1〜出租數量。
這是一個任務,我試圖通過 - 參數是一個新插入的列(num_rentals),它必須增加每個租賃...我同意可以有更簡單的方法來做到這一點。感謝您的幫助。修正它吧! – 2012-08-08 19:17:24