declare @objectID int;
select @objectID = object_id from sys.triggers where parent_id = object_id(N'dbo.UserSecurity') and name= N'trUserSecurity_Delete';
declare @createOrAlter nvarchar(6);
set @createOrAlter = case when @objectID is null then N'create' else N'alter' end;
exec (@createOrAlter + N' trigger dbo.trUserSecurity_Delete
on dbo.UserSecurity after delete
as
begin
    set nocount on;
    update dbo.DatabaseInfo set ConnectionCacheID = newid(), IntelligentCacheID = newid();
end;');