If not exists (select 1 from tempdb



if not exists (select 1 from tempdb..sysobjects

where type = 'U' and name = 'DBA_syslogins')

create table tempdb..DBA_syslogins

(name sysname not null primary key)

go

declare @body varchar(8000)

set @body = 'New logins: '

-- If it's not the first time it executes:

if exists (select 1 from tempdb..DBA_syslogins)

begin

-- If there are any new logins:

if exists (select 1 from master..syslogins

where name not in

(select name from tempdb..DBA_syslogins))

begin

select @body = @body + name + ','

from master..syslogins

where name not in (select name from tempdb..DBA_syslogins)

-- Omit the last comma:

select @body = substring(@body,1,LEN(@body)-1)

-- Send the message to the DBA with new logins:

EXEC msdb.dbo.sp_send_dbmail

@recipients=N'michelle.gutzait@Adventure-',

@body=N'New logins have been created.'

end

end

-- Modify the table’s content anyway

-- (since we’re not checking for deleted logins):

truncate table tempdb..DBA_syslogins

insert into tempdb..DBA_syslogins (name)

select name from master..syslogins

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download