SQL Server 2008 - Help writing simple INSERT Trigger

前端 未结 3 1729
北荒
北荒 2020-11-29 10:53

This is with Microsoft SQL Server 2008.

I\'ve got 2 tables, Employee and EmployeeResult and I\'m trying to write a simple INSERT trigger on EmployeeResult that does

3条回答
  •  没有蜡笔的小新
    2020-11-29 11:38

    check this code:

    CREATE TRIGGER trig_Update_Employee ON [EmployeeResult] FOR INSERT AS Begin   
        Insert into Employee (Name, Department)  
        Select Distinct i.Name, i.Department   
            from Inserted i
            Left Join Employee e on i.Name = e.Name and i.Department = e.Department
            where e.Name is null
    End
    

提交回复
热议问题