if object_id(N'dbo.tr_Department_Delete') is null
begin
    exec ('create trigger dbo.tr_Department_Delete
on dbo.Department
for delete
as 
begin
    set nocount on

    insert into dbo.DepartmentHistory (HistoryType, DepartmentID, Name, Description, ModifiedDate, ModifiedUserName, ModifiedLoggedUserName)
    select ''D'', ID, Name, Description, getdate(), ModifiedUserName, ModifiedLoggedUserName
    from deleted
end');
end