You are on page 1of 1

USE AdventureWorks2005

CREATE TRIGGER [HumanResources].[trgDepartment] ON [HumanResources].[Department]


AFTER UPDATE AS
BEGIN
UPDATE [HumanResources].[Department]
SET [HumanResources].[Department].[ModifiedDate] = GETDATE()
FROM Inserted
WHERE Inserted.[DepartmentID] = [HumanResources].[Department].[DepartmentID];
END;

/* ACTIVITY IMPLEMENTING TRIGGERS */


CREATE VIEW vwEmployee AS
SELECT e.EmployeeID AS 'Employee ID',
h.Firstname AS 'Employee Name', g.Name AS 'Department Name',
e.HireDate AS 'Date Of Joining', j.AddressLine1 AS 'Employee Address'
FROM HumanResources.Employee AS e
JOIN HumanResources.EmployeeDepartmentHistory AS f ON
e.EmployeeID = f.EmployeeID JOIN HumanResources.Department AS g
ON f.DepartmentID = g.DepartmentID
JOIN Person.Contact AS h ON e.ContactID = h.ContactID
JOIN HumanResources.EmployeeAddress AS i ON
e.EmployeeID = i.EmployeeID JOIN Person.Address AS j ON i.AddressID = j.AddressI
D

USE AdventureWorks2005
Select e.EmployeeID,e.Title, eph.Rate,eph.PayFrequency FROM HumanResources.Emplo
yee e
JOIN HumanResources.EmployeePayHistory eph ON e.EmployeeID = eph.EmployeeID
CREATE PROCEDURE PrcDept
AS
BEGIN
SELECT Name FROM HumanResources.Department
END
DROP PROCEDURE PrcDept
CREATE FUNCTION fx_Department_GName ( @GrName nvarchar(20) )
RETURNS Table
AS
RETURN (
SELECT * FROM HumanResources.Department WHERE GroupName=@GrName
)
GO
SELECT * FROM fx_Department_GName('Manufacturing')

You might also like