が、これは私がトリガで列を識別できないのはなぜですか?私は特定のデータセットのトリガーを作成しようとしています
Create trigger tr_minimum_salary
On tble_SalesReps_TR
After Update as
If update(salary) and datediff(YY,DateOfHire,getdate())>=15
Begin
Raiserror('Employees with more than 15 years of experience cannot recieve less than 100,000 $',0,1)
Rollback
Return
END
を使用していたコードであることは言う私にエラーを与える「無効な列名をDateofHire」
次のコードは、動作しますが
Select * from tble_SalesReps_TR
Where datediff(YY,DateOfHire,getdate())>=15
トリガーコードには何が間違っていますか?
編集:ここで仕事をした別のトリガコードは
Create trigger tr_nochange_december
On tbls_products_tr
After Update as
If update(UnitsOnOrder) and datepart(m,(getdate()))<>12
Begin
Raiserror('These products can only be purchased in December',0,1)
Rollback
Return
END
また、ここで注意してください。 UPDATE関数は、値が同じかどうかを評価しません。その列が元の更新ステートメントに含まれているかどうかを確認するだけです。これは非常に一般的な誤解です。 UPDATE(Salary)は、値が変更されていない場合でもtrueを返します。 –