Day3 of the SQL Server database triggers

Recently doing a personnel management system written a few simple flip-flop

1. In the Delete employee information table in staff time zone information results prompt the employee information is deleted

 

the Trigger the Test the Create
ON employee information table
the After the Delete
as
the SELECT job number is deleted as staff no, name, phone number deleted from
Go
2. When you delete information such as the dismissal of employees also deletes the corresponding information in other tables

create trigger yuan_delete on employee information table
the After the Delete
AS
DECLARE @ work number char (10)
the SELECT @ work number = job number from deleted
delete from subscription information table where job number = @ work number
delete from finding employment information table where job number = @ work No.
delete from academic information table where the job number job number = @
Go
3. Add employee information to correspond to delete employee turnover information table information

CREATE TRIGGER yuan_lizhi ON employee information table
an AFTER the DELETE
the AS
DECLARE @ job number char (10)
SELECT @ station number = station number from deleted
the INSERT the INTO separation information table
values
(@ job number, CONVERT (varchar, GETDATE () , 120), ( select names from deleted), (select gender from deleted), (select phones from deleted), (select date of birth from deleted), (select addresses from deleted), (select department number from finding employment information table where job number = @ work number ), (select job ID from finding employment information table where job number = @ work number))
GO
4. determine overtime pay based on the number of days the number of days the miners employees

CREATE TRIGGER test2 ON examination table records
an AFTER the INSERT
the AS
DECLARE @a char (10), B @ BIGINT, BIGINT @ C, D @ char (10), E @ VARCHAR (10), @ DATE DATE, salary1 int @, @ salary2 int, int salary3 @, @ SA int
the begin
SET @ B = 3,000,000,001
SET @ @ C = B + (the SELECT COUNT (*) the FROM payroll record table)
SET A = @ Cast (AS @c char (10))
SET @e = (the CONVERT (VARCHAR (10), GETDATE (), 120))
SET DATE = @ Cast (@e AS VARCHAR (30))
SET @ D = (SELECT inserted The job number from)
SET @ SA = (SELECT employee salary from floor scale
where @ d = job number)
SET @ salary1 = (SELECT absenteeism days from inserted The) * 100
SET @ salary2 = (SELECT overtime number from days inserted The) * 50
SET @ salary3 = (@ SA) + @ salary2- @ salary1

INSERT payroll records into the table
values (@ A, @ DATE, @ D, SA @, @ salary2, salary1 @, @ salary3)
End
GO
--------------------- !

Guess you like

Origin www.cnblogs.com/ly570/p/10961733.html