因此,我正在使用的環境是MS SQL Server Management Studio,它被證明是觸發器非常痛苦的事情。我想要做的是創建一個觸發器,如果新員工的薪水低於他們分配的部門中的所有其他員工的薪水,則會在新表中插入新員工的信息(SALARY_VIOLATION_NEW_EMP)。在觸發器中實現條件
我有它在哪裏插入新的信息到新表中,我只是無法弄清楚如何實現條件。這是我到目前爲止有:
CREATE TRIGGER SALARY_VIOLATION
ON EMPLOYEE
AFTER INSERT
AS
BEGIN
declare @newFname varchar(50), @newLname varchar(50), @newSsn char(9), @newSex char(1),
@newSalary decimal(10,2), @newSuper_ssn char(9), @newDno int;
select @newFname = Fname,
@newLname = Lname,
@newSsn = Ssn,
@newSex = Sex,
@newSalary = Salary,
@newSuper_ssn = Super_ssn,
@newDno = Dno from inserted;
INSERT INTO SALARY_VIOLATION_NEW_EMP(FirstName,LastName,Ssn,Sex,Salary,Super_ssn,Dno)
values(@newFname, @newLname, @newSsn, @newSex, @newSalary, @newSuper_ssn, @newDno);
END
GO
爲了節省時間我有滿足兩個表的測試數據:
insert into EMPLOYEE values ('John',null,'doe','234536779',null,null,'M', 20000,'987654321',4)
以供將來參考MySQL是一個不同的數據庫引擎。 – Zane 2014-11-05 21:48:58
你插入的字段中有哪些部門信息是DNO? – 2014-11-05 21:57:07