Wednesday, October 12, 2011

TRIGGER Sql-server on OBIEE user table insert and delete

CREATE

TRIGGER [dbo].[OBIEE_USERSTRI_INS]

ON

[dbo].[WC_OBIEE_USERS]

FOR

INSERT

AS

BEGIN

DECLARE

@USERNAME VARCHAR(100)

DECLARE

@GROUPNAME VARCHAR(100)

SELECT

@USERNAME = (SELECT USERNAME FROM Inserted)

SELECT

@GROUPNAME = (SELECT GROUPNAME FROM Inserted)

insert

into WC_OBIEE_AUDIT(USERNAME,GROUPNAME,USERID,DATEUPD,WORKSTN,[ACTION])

select

@USERNAME,@GROUPNAME,SYSTEM_USER,getdate(),host_name() ,'Insert'

/*

insert into WC_OBIEE_AUDIT(USERNAME,GROUPNAME,USERID,DATEUPD,WORKSTN,[ACTION])

select a.[USERNAME],a.GROUPNAME,SYSTEM_USER,getdate(),host_name() ,'Insert' "ACTION" from WC_OBIEE_USERS a

left outer join WC_OBIEE_AUDIT b on a.[USERNAME]=b.[USERNAME] and a.[GROUPNAME]=b.[GROUPNAME]

where b.[USERNAME] is null

*/

END

Create

TRIGGER [dbo].[OBIEE_USERSTRI_DEL]

ON

[dbo].[WC_OBIEE_USERS]

FOR

DELETE

AS

BEGIN

DECLARE

@USERNAME1 VARCHAR(100)

DECLARE

@GROUPNAME1 VARCHAR(2000)

SELECT

@USERNAME1 =USERNAME,@GROUPNAME1=GROUPNAME FROM Deleted

insert

into WC_OBIEE_AUDIT(USERNAME,GROUPNAME,USERID,DATEUPD,WORKSTN,[ACTION])

select

@USERNAME1,@GROUPNAME1,SYSTEM_USER,getdate(),host_name() ,'Delete'

/*

insert into WC_OBIEE_AUDIT(USERNAME,GROUPNAME,USERID,DATEUPD,WORKSTN,[ACTION])

select a.[USERNAME],a.[GROUPNAME],SYSTEM_USER,getdate(),host_name() ,'Delete' "ACTION" from WC_OBIEE_AUDIT a

left outer join WC_OBIEE_USERS b on a.[USERNAME]=b.[USERNAME] and a.[GROUPNAME]=b.[GROUPNAME]

where b.[USERNAME] is null

*/

END

No comments: