当雇员的姓名被更改时,用户表中的用户姓名同时更新,雇员表与用户表的WorkNumber是Primary key 与Foreign key的关系。
CREATE TRIGGER [dbo].[tri_Employee_UpdateEmployeeName] ON [dbo].[Employee]
FOR UPDATE
AS
DECLARE
@EmployeeName nvarchar(50),
@WorkNumber int
SELECT @EmployeeName=[EmployeeName],@WorkNumber =[WorkNumber] FROM INSERTED
IF UPDATE([EmployeeName])
BEGIN
UPDATE [Users] SET [Name] =@EmployeeName WHERE [WorkNumber]= @WorkNumber
END