如何将MSSQL触发器转换为MySql触发器而不是MSSQL中使用的触发器

时间:2017-07-13 05:47:03

标签: php mysql sql-server triggers

如何将MSSQL触发器转换为MySql触发器而不是MSSQL中使用的触发器

是否有在线转换工具将此MSSQL触发器更改为MySql Trigger

可用于MYSQL的语法是什么:
    INSTEAD OF INSERT,UPDATE,DELETE

  /******Object: MYSQL TRIGGER.[T1_USERS]  Script Date: 13-Jul-2017 09:41:22 ******/

DROP TRIGGER  IF EXISTS T1_USERS;

CREATE TRIGGER T1_USERS ON USERS
INSTEAD OF INSERT, UPDATE, DELETE
AS
DECLARE
   @OLD_CODE                           varchar(10),
   @NEW_CODE                           varchar(10),
   @OLD_NAME                           varchar(40),
   @NEW_NAME                           varchar(40),
   @OLD_PASSWORD                       varchar(512),
   @NEW_PASSWORD                       varchar(512),
   @OLD_GROUP_CODE                     varchar(10),
   @NEW_GROUP_CODE                     varchar(10),
   @OLD_ACTIVE                         varchar(1),
   @NEW_ACTIVE                         varchar(1),
   @OLD_LOCKED                         varchar(1),
   @NEW_LOCKED                         varchar(1),
   @OLD_CHANGE_PASSWORD_FLAG           varchar(1),
   @NEW_CHANGE_PASSWORD_FLAG           varchar(1),
   @OLD_NO_OF_ATTEMPTS                 decimal(6, 0),
   @NEW_NO_OF_ATTEMPTS                 decimal(6, 0),
   @OLD_LAST_PASSWORD_CHANGE           datetime,
   @NEW_LAST_PASSWORD_CHANGE           datetime,
   @OLD_MDW_ID                         [varchar](20),
   @NEW_MDW_ID                         [varchar](20),
   @OLD_CHG_ID                         [varchar](20),
   @NEW_CHG_ID                         [varchar](20),
   @OLD_CREATED_BY_MODULE              [varchar](250),
   @NEW_CREATED_BY_MODULE              [varchar](250),
   @OLD_CREATED_BY_USER_CODE           [varchar](50),
   @NEW_CREATED_BY_USER_CODE           [varchar](50),
   @OLD_CREATED_BY_OS_USER             [varchar](100),
   @NEW_CREATED_BY_OS_USER             [varchar](100),
   @OLD_CREATED_BY_USER_NAME           [varchar](100),
   @NEW_CREATED_BY_USER_NAME           [varchar](100),
   @OLD_CREATED_ON                     [datetime],
   @NEW_CREATED_ON                     [datetime],
   @OLD_CHANGED_BY_MODULE              [varchar](250),
   @NEW_CHANGED_BY_MODULE              [varchar](250),
   @OLD_CHANGED_BY_USER_CODE           [varchar](50),
   @NEW_CHANGED_BY_USER_CODE           [varchar](50),
   @OLD_CHANGED_BY_OS_USER             [varchar](100),
   @NEW_CHANGED_BY_OS_USER             [varchar](100),
   @OLD_CHANGED_BY_USER_NAME           [varchar](100),
   @NEW_CHANGED_BY_USER_NAME           [varchar](100),
   @OLD_CHANGED_ON                     [datetime],
   @NEW_CHANGED_ON                     [datetime],
   @RowsInserted                       [integer],
   @RowsDeleted                        [integer],
   @RowsRecordID                       [integer],
   @Mode                               [varchar](1),
   @ChangeID                           [numeric],
   @ActionID                           [numeric],
   @Action                             [varchar](30),
   @Action1                            [varchar](30),
   @Action2                            [varchar](30),
   @PosCode                            [varchar](30),
   @mMachine                           [varchar](150),
   @mSessionID                         [decimal](9,0),
   @mAppUserCode                       [varchar](50),
   @mOSUser                            [varchar](50),
   @mAppUserName                       [varchar](150),
   @mModuleName                        [varchar](250)
BEGIN

SELECT @RowsInserted = COUNT(*) FROM Inserted
SELECT @RowsDeleted  = COUNT(*) FROM Deleted
SELECT @RowsRecordID = COUNT(*) FROM Inserted I, Deleted D WHERE (I.CODE=D.CODE)
SELECT * INTO #tempInserted FROM Inserted
SELECT * INTO #tempDeleted  FROM Deleted
SET @ActionID = NEXT VALUE FOR ACTION_ID_SEQ

SELECT 
   @mAppUserCode=APP_USERCODE,
   @mOSUser=OS_USER,
   @mAppUserName=APP_USERNAME,
   @mModuleName=MODULE_NAME,
   @mMachine=MACHINE,
   @mSessionID=SESSION_ID
FROM
   DB_SESSION_VIEW

IF (@RowsInserted>0) AND (@RowsDeleted=0)
   BEGIN
   UPDATE #tempInserted SET
      CREATED_BY_MODULE    = @mModuleName,
      CREATED_BY_USER_CODE = @mAppUserCode,
      CREATED_BY_OS_USER   = @mOSUser,
      CREATED_BY_USER_NAME = @mAppUserName,
      CREATED_ON           = GetDate()
   END
ELSE IF (@RowsInserted>0) AND (@RowsDeleted>0)
   BEGIN
   UPDATE #tempInserted SET
      CHANGED_BY_MODULE    = @mModuleName,
      CHANGED_BY_USER_CODE = @mAppUserCode,
      CHANGED_BY_OS_USER   = @mOSUser,
      CHANGED_BY_USER_NAME = @mAppUserName,
      CHANGED_ON           = GetDate()
   END

DECLARE InsertedCursor CURSOR FOR
   SELECT
      I.CODE, 
      I.NAME, 
      I.PASSWORD, 
      I.GROUP_CODE, 
      I.ACTIVE, 
      I.LOCKED, 
      I.CHANGE_PASSWORD_FLAG, 
      I.NO_OF_ATTEMPTS, 
      I.LAST_PASSWORD_CHANGE, 
      I.MDW_ID,
      I.CHG_ID,
      I.CREATED_BY_MODULE,
      I.CREATED_BY_USER_CODE,
      I.CREATED_BY_OS_USER,
      I.CREATED_BY_USER_NAME,
      I.CREATED_ON,
      I.CHANGED_BY_MODULE,
      I.CHANGED_BY_USER_CODE,
      I.CHANGED_BY_OS_USER,
      I.CHANGED_BY_USER_NAME,
      I.CHANGED_ON
   FROM
      #tempInserted I
   WHERE
      NOT EXISTS (SELECT D.CODE FROM #tempDeleted D WHERE (I.CODE=D.CODE))

DECLARE UpdatedCursor CURSOR FOR
   SELECT
      I.CODE                            AS      NEW_CODE,
      I.NAME                            AS      NEW_NAME,
      I.PASSWORD                        AS      NEW_PASSWORD,
      I.GROUP_CODE                      AS      NEW_GROUP_CODE,
      I.ACTIVE                          AS      NEW_ACTIVE,
      I.LOCKED                          AS      NEW_LOCKED,
      I.CHANGE_PASSWORD_FLAG            AS      NEW_CHANGE_PASSWORD_FLAG,
      I.NO_OF_ATTEMPTS                  AS      NEW_NO_OF_ATTEMPTS,
      I.LAST_PASSWORD_CHANGE            AS      NEW_LAST_PASSWORD_CHANGE,
      I.MDW_ID                          AS      NEW_MDW_ID,
      I.CHG_ID                          AS      NEW_CHG_ID,
      I.CREATED_BY_MODULE               AS      NEW_CREATED_BY_MODULE,
      I.CREATED_BY_USER_CODE            AS      NEW_CREATED_BY_USER_CODE,
      I.CREATED_BY_OS_USER              AS      NEW_CREATED_BY_OS_USER,
      I.CREATED_BY_USER_NAME            AS      NEW_CREATED_BY_USER_NAME,
      I.CREATED_ON                      AS      NEW_CREATED_ON,
      I.CHANGED_BY_MODULE               AS      NEW_CHANGED_BY_MODULE,
      I.CHANGED_BY_USER_CODE            AS      NEW_CHANGED_BY_USER_CODE,
      I.CHANGED_BY_OS_USER              AS      NEW_CHANGED_BY_OS_USER,
      I.CHANGED_BY_USER_NAME            AS      NEW_CHANGED_BY_USER_NAME,
      I.CHANGED_ON                      AS      NEW_CHANGED_ON,
      D.CODE                            AS      OLD_CODE,
      D.NAME                            AS      OLD_NAME,
      D.PASSWORD                        AS      OLD_PASSWORD,
      D.GROUP_CODE                      AS      OLD_GROUP_CODE,
      D.ACTIVE                          AS      OLD_ACTIVE,
      D.LOCKED                          AS      OLD_LOCKED,
      D.CHANGE_PASSWORD_FLAG            AS      OLD_CHANGE_PASSWORD_FLAG,
      D.NO_OF_ATTEMPTS                  AS      OLD_NO_OF_ATTEMPTS,
      D.LAST_PASSWORD_CHANGE            AS      OLD_LAST_PASSWORD_CHANGE,
      D.MDW_ID                          AS      OLD_MDW_ID,
      D.CHG_ID                          AS      OLD_CHG_ID,
      D.CREATED_BY_MODULE               AS      OLD_CREATED_BY_MODULE,
      D.CREATED_BY_USER_CODE            AS      OLD_CREATED_BY_USER_CODE,
      D.CREATED_BY_OS_USER              AS      OLD_CREATED_BY_OS_USER,
      D.CREATED_BY_USER_NAME            AS      OLD_CREATED_BY_USER_NAME,
      D.CREATED_ON                      AS      OLD_CREATED_ON,
      D.CHANGED_BY_MODULE               AS      OLD_CHANGED_BY_MODULE,
      D.CHANGED_BY_USER_CODE            AS      OLD_CHANGED_BY_USER_CODE,
      D.CHANGED_BY_OS_USER              AS      OLD_CHANGED_BY_OS_USER,
      D.CHANGED_BY_USER_NAME            AS      OLD_CHANGED_BY_USER_NAME,
      D.CHANGED_ON                      AS      OLD_CHANGED_ON
   FROM
      #tempInserted I,
      #tempDeleted  D
   WHERE
      (I.CODE=D.CODE)

DECLARE DeletedCursor CURSOR FOR
   SELECT
      D.CODE, 
      D.NAME, 
      D.PASSWORD, 
      D.GROUP_CODE, 
      D.ACTIVE, 
      D.LOCKED, 
      D.CHANGE_PASSWORD_FLAG, 
      D.NO_OF_ATTEMPTS, 
      D.LAST_PASSWORD_CHANGE, 
      D.MDW_ID,
      D.CHG_ID,
      D.CREATED_BY_MODULE,
      D.CREATED_BY_USER_CODE,
      D.CREATED_BY_OS_USER,
      D.CREATED_BY_USER_NAME,
      D.CREATED_ON,
      D.CHANGED_BY_MODULE,
      D.CHANGED_BY_USER_CODE,
      D.CHANGED_BY_OS_USER,
      D.CHANGED_BY_USER_NAME,
      D.CHANGED_ON
   FROM
      #tempDeleted D
   WHERE
      NOT EXISTS (SELECT I.CODE FROM #tempInserted I WHERE (D.CODE=I.CODE))

DELETE FROM USERS WHERE EXISTS (SELECT * FROM Deleted D WHERE (USERS.CODE=D.CODE))

INSERT INTO USERS
   (
   CODE, 
   NAME, 
   PASSWORD, 
   GROUP_CODE, 
   ACTIVE, 
   LOCKED, 
   CHANGE_PASSWORD_FLAG, 
   NO_OF_ATTEMPTS, 
   LAST_PASSWORD_CHANGE, 
   MDW_ID,
   CHG_ID,
   CREATED_BY_MODULE,
   CREATED_BY_USER_CODE,
   CREATED_BY_OS_USER,
   CREATED_BY_USER_NAME,
   CREATED_ON,
   CHANGED_BY_MODULE,
   CHANGED_BY_USER_CODE,
   CHANGED_BY_OS_USER,
   CHANGED_BY_USER_NAME,
   CHANGED_ON
   )
SELECT
   CODE, 
   NAME, 
   PASSWORD, 
   GROUP_CODE, 
   ACTIVE, 
   LOCKED, 
   CHANGE_PASSWORD_FLAG, 
   NO_OF_ATTEMPTS, 
   LAST_PASSWORD_CHANGE, 
   MDW_ID,
   CHG_ID,
   CREATED_BY_MODULE,
   CREATED_BY_USER_CODE,
   CREATED_BY_OS_USER,
   CREATED_BY_USER_NAME,
   CREATED_ON,
   CHANGED_BY_MODULE,
   CHANGED_BY_USER_CODE,
   CHANGED_BY_OS_USER,
   CHANGED_BY_USER_NAME,
   CHANGED_ON
FROM
   #tempInserted

OPEN InsertedCursor
OPEN UpdatedCursor
OPEN DeletedCursor

SET  @Action  = 'INSERT'
SET  @Action1 = 'INSERT'
FETCH NEXT FROM InsertedCursor INTO
   @NEW_CODE, 
   @NEW_NAME, 
   @NEW_PASSWORD, 
   @NEW_GROUP_CODE, 
   @NEW_ACTIVE, 
   @NEW_LOCKED, 
   @NEW_CHANGE_PASSWORD_FLAG, 
   @NEW_NO_OF_ATTEMPTS, 
   @NEW_LAST_PASSWORD_CHANGE, 
   @NEW_MDW_ID,
   @NEW_CHG_ID,
   @NEW_CREATED_BY_MODULE,
   @NEW_CREATED_BY_USER_CODE,
   @NEW_CREATED_BY_OS_USER,
   @NEW_CREATED_BY_USER_NAME,
   @NEW_CREATED_ON,
   @NEW_CHANGED_BY_MODULE,
   @NEW_CHANGED_BY_USER_CODE,
   @NEW_CHANGED_BY_OS_USER,
   @NEW_CHANGED_BY_USER_NAME,
   @NEW_CHANGED_ON
WHILE (@@FETCH_STATUS = 0)
   BEGIN
   SET @ChangeID = NEXT VALUE FOR CHANGE_ID_SEQ
   INSERT INTO USERS_LOG
      (
      CHANGE_ID,
      ACTION,
      NEW_OLD,
      CODE, 
      NAME, 
      PASSWORD, 
      GROUP_CODE, 
      ACTIVE, 
      LOCKED, 
      CHANGE_PASSWORD_FLAG, 
      NO_OF_ATTEMPTS, 
      LAST_PASSWORD_CHANGE, 
      MDW_ID,
      CHG_ID,
      CREATED_BY_MODULE,
      CREATED_BY_USER_CODE,
      CREATED_BY_OS_USER,
      CREATED_BY_USER_NAME,
      CREATED_ON,
      CHANGED_BY_MODULE,
      CHANGED_BY_USER_CODE,
      CHANGED_BY_OS_USER,
      CHANGED_BY_USER_NAME,
      CHANGED_ON,
      ACTION_ID,
      CHG_DATE_TIME,
      CHG_USER_ID,
      CHG_MACHINE_NAME,
      CHG_SESSION_ID
      )
   VALUES
      (
      @ChangeID,
      @Action1,
      'NEW',
      @NEW_CODE, 
      @NEW_NAME, 
      @NEW_PASSWORD, 
      @NEW_GROUP_CODE, 
      @NEW_ACTIVE, 
      @NEW_LOCKED, 
      @NEW_CHANGE_PASSWORD_FLAG, 
      @NEW_NO_OF_ATTEMPTS, 
      @NEW_LAST_PASSWORD_CHANGE, 
      @NEW_MDW_ID,
      @NEW_CHG_ID,
      @NEW_CREATED_BY_MODULE,
      @NEW_CREATED_BY_USER_CODE,
      @NEW_CREATED_BY_OS_USER,
      @NEW_CREATED_BY_USER_NAME,
      @NEW_CREATED_ON,
      @NEW_CHANGED_BY_MODULE,
      @NEW_CHANGED_BY_USER_CODE,
      @NEW_CHANGED_BY_OS_USER,
      @NEW_CHANGED_BY_USER_NAME,
      @NEW_CHANGED_ON,
      @ActionID,
      GetDate(),
      @mAppUserCode,
      @mMachine,
      @mSessionID
      )

   FETCH NEXT FROM InsertedCursor INTO
      @NEW_CODE, 
      @NEW_NAME, 
      @NEW_PASSWORD, 
      @NEW_GROUP_CODE, 
      @NEW_ACTIVE, 
      @NEW_LOCKED, 
      @NEW_CHANGE_PASSWORD_FLAG, 
      @NEW_NO_OF_ATTEMPTS, 
      @NEW_LAST_PASSWORD_CHANGE, 
      @NEW_MDW_ID,
      @NEW_CHG_ID,
      @NEW_CREATED_BY_MODULE,
      @NEW_CREATED_BY_USER_CODE,
      @NEW_CREATED_BY_OS_USER,
      @NEW_CREATED_BY_USER_NAME,
      @NEW_CREATED_ON,
      @NEW_CHANGED_BY_MODULE,
      @NEW_CHANGED_BY_USER_CODE,
      @NEW_CHANGED_BY_OS_USER,
      @NEW_CHANGED_BY_USER_NAME,
      @NEW_CHANGED_ON
   END

SET  @Action = 'UPDATE'
FETCH NEXT FROM UpdatedCursor INTO
   @NEW_CODE, 
   @NEW_NAME, 
   @NEW_PASSWORD, 
   @NEW_GROUP_CODE, 
   @NEW_ACTIVE, 
   @NEW_LOCKED, 
   @NEW_CHANGE_PASSWORD_FLAG, 
   @NEW_NO_OF_ATTEMPTS, 
   @NEW_LAST_PASSWORD_CHANGE, 
   @NEW_MDW_ID,
   @NEW_CHG_ID,
   @NEW_CREATED_BY_MODULE,
   @NEW_CREATED_BY_USER_CODE,
   @NEW_CREATED_BY_OS_USER,
   @NEW_CREATED_BY_USER_NAME,
   @NEW_CREATED_ON,
   @NEW_CHANGED_BY_MODULE,
   @NEW_CHANGED_BY_USER_CODE,
   @NEW_CHANGED_BY_OS_USER,
   @NEW_CHANGED_BY_USER_NAME,
   @NEW_CHANGED_ON,
   @OLD_CODE, 
   @OLD_NAME, 
   @OLD_PASSWORD, 
   @OLD_GROUP_CODE, 
   @OLD_ACTIVE, 
   @OLD_LOCKED, 
   @OLD_CHANGE_PASSWORD_FLAG, 
   @OLD_NO_OF_ATTEMPTS, 
   @OLD_LAST_PASSWORD_CHANGE, 
   @OLD_MDW_ID,
   @OLD_CHG_ID,
   @OLD_CREATED_BY_MODULE,
   @OLD_CREATED_BY_USER_CODE,
   @OLD_CREATED_BY_OS_USER,
   @OLD_CREATED_BY_USER_NAME,
   @OLD_CREATED_ON,
   @OLD_CHANGED_BY_MODULE,
   @OLD_CHANGED_BY_USER_CODE,
   @OLD_CHANGED_BY_OS_USER,
   @OLD_CHANGED_BY_USER_NAME,
   @OLD_CHANGED_ON
WHILE (@@FETCH_STATUS = 0)
   BEGIN
   SET @ChangeID = NEXT VALUE FOR CHANGE_ID_SEQ
   IF (@OLD_CODE=@NEW_CODE)
      BEGIN
      SET  @Action1 = 'UPDATE'
      SET  @Action2 = 'UPDATE'
      END
   ELSE
      BEGIN
      SET  @Action1 = 'DELETE'
      SET  @Action2 = 'INSERT'
      END

   INSERT INTO USERS_LOG
      (
      CHANGE_ID,
      ACTION,
      NEW_OLD,
      CODE, 
      NAME, 
      PASSWORD, 
      GROUP_CODE, 
      ACTIVE, 
      LOCKED, 
      CHANGE_PASSWORD_FLAG, 
      NO_OF_ATTEMPTS, 
      LAST_PASSWORD_CHANGE, 
      MDW_ID,
      CHG_ID,
      CREATED_BY_MODULE,
      CREATED_BY_USER_CODE,
      CREATED_BY_OS_USER,
      CREATED_BY_USER_NAME,
      CREATED_ON,
      CHANGED_BY_MODULE,
      CHANGED_BY_USER_CODE,
      CHANGED_BY_OS_USER,
      CHANGED_BY_USER_NAME,
      CHANGED_ON,
      ACTION_ID,
      CHG_DATE_TIME,
      CHG_USER_ID,  
      CHG_MACHINE_NAME,
      CHG_SESSION_ID
      )
   VALUES
      (
      @ChangeID,
      @Action1,
      'OLD',
      @OLD_CODE, 
      @OLD_NAME, 
      @OLD_PASSWORD, 
      @OLD_GROUP_CODE, 
      @OLD_ACTIVE, 
      @OLD_LOCKED, 
      @OLD_CHANGE_PASSWORD_FLAG, 
      @OLD_NO_OF_ATTEMPTS, 
      @OLD_LAST_PASSWORD_CHANGE, 
      @OLD_MDW_ID,
      @OLD_CHG_ID,
      @OLD_CREATED_BY_MODULE,
      @OLD_CREATED_BY_USER_CODE,
      @OLD_CREATED_BY_OS_USER,
      @OLD_CREATED_BY_USER_NAME,
      @OLD_CREATED_ON,
      @OLD_CHANGED_BY_MODULE,
      @OLD_CHANGED_BY_USER_CODE,
      @OLD_CHANGED_BY_OS_USER,
      @OLD_CHANGED_BY_USER_NAME,
      @OLD_CHANGED_ON,
      @ActionID,
      GetDate(),
      @mAppUserCode,
      @mMachine,
      @mSessionID
      )
   INSERT INTO USERS_LOG
      (
      CHANGE_ID,
      ACTION,
      NEW_OLD,
      CODE, 
      NAME, 
      PASSWORD, 
      GROUP_CODE, 
      ACTIVE, 
      LOCKED, 
      CHANGE_PASSWORD_FLAG, 
      NO_OF_ATTEMPTS, 
      LAST_PASSWORD_CHANGE, 
      MDW_ID,
      CHG_ID,
      CREATED_BY_MODULE,
      CREATED_BY_USER_CODE,
      CREATED_BY_OS_USER,
      CREATED_BY_USER_NAME,
      CREATED_ON,
      CHANGED_BY_MODULE,
      CHANGED_BY_USER_CODE,
      CHANGED_BY_OS_USER,
      CHANGED_BY_USER_NAME,
      CHANGED_ON,
      ACTION_ID,
      CHG_DATE_TIME,
      CHG_USER_ID,
      CHG_MACHINE_NAME,
      CHG_SESSION_ID
      )
   VALUES
      (
      @ChangeID,
      @Action2,
      'NEW',
      @NEW_CODE, 
      @NEW_NAME, 
      @NEW_PASSWORD, 
      @NEW_GROUP_CODE, 
      @NEW_ACTIVE, 
      @NEW_LOCKED, 
      @NEW_CHANGE_PASSWORD_FLAG, 
      @NEW_NO_OF_ATTEMPTS, 
      @NEW_LAST_PASSWORD_CHANGE, 
      @NEW_MDW_ID,
      @NEW_CHG_ID,
      @NEW_CREATED_BY_MODULE,
      @NEW_CREATED_BY_USER_CODE,
      @NEW_CREATED_BY_OS_USER,
      @NEW_CREATED_BY_USER_NAME,
      @NEW_CREATED_ON,
      @NEW_CHANGED_BY_MODULE,
      @NEW_CHANGED_BY_USER_CODE,
      @NEW_CHANGED_BY_OS_USER,
      @NEW_CHANGED_BY_USER_NAME,
      @NEW_CHANGED_ON,
      @ActionID,
      GetDate(),
      @mAppUserCode,
      @mMachine,
      @mSessionID
      )

   FETCH NEXT FROM UpdatedCursor INTO
      @NEW_CODE, 
      @NEW_NAME, 
      @NEW_PASSWORD, 
      @NEW_GROUP_CODE, 
      @NEW_ACTIVE, 
      @NEW_LOCKED, 
      @NEW_CHANGE_PASSWORD_FLAG, 
      @NEW_NO_OF_ATTEMPTS, 
      @NEW_LAST_PASSWORD_CHANGE, 
      @NEW_MDW_ID,
      @NEW_CHG_ID,
      @NEW_CREATED_BY_MODULE,
      @NEW_CREATED_BY_USER_CODE,
      @NEW_CREATED_BY_OS_USER,
      @NEW_CREATED_BY_USER_NAME,
      @NEW_CREATED_ON,
      @NEW_CHANGED_BY_MODULE,
      @NEW_CHANGED_BY_USER_CODE,
      @NEW_CHANGED_BY_OS_USER,
      @NEW_CHANGED_BY_USER_NAME,
      @NEW_CHANGED_ON,
      @OLD_CODE, 
      @OLD_NAME, 
      @OLD_PASSWORD, 
      @OLD_GROUP_CODE, 
      @OLD_ACTIVE, 
      @OLD_LOCKED, 
      @OLD_CHANGE_PASSWORD_FLAG, 
      @OLD_NO_OF_ATTEMPTS, 
      @OLD_LAST_PASSWORD_CHANGE, 
      @OLD_MDW_ID,
      @OLD_CHG_ID,
      @OLD_CREATED_BY_MODULE,
      @OLD_CREATED_BY_USER_CODE,
      @OLD_CREATED_BY_OS_USER,
      @OLD_CREATED_BY_USER_NAME,
      @OLD_CREATED_ON,
      @OLD_CHANGED_BY_MODULE,
      @OLD_CHANGED_BY_USER_CODE,
      @OLD_CHANGED_BY_OS_USER,
      @OLD_CHANGED_BY_USER_NAME,
      @OLD_CHANGED_ON
   END
SET  @Action  = 'DELETE'
SET  @Action1 = 'DELETE'
FETCH NEXT FROM DeletedCursor INTO
   @OLD_CODE, 
   @OLD_NAME, 
   @OLD_PASSWORD, 
   @OLD_GROUP_CODE, 
   @OLD_ACTIVE, 
   @OLD_LOCKED, 
   @OLD_CHANGE_PASSWORD_FLAG, 
   @OLD_NO_OF_ATTEMPTS, 
   @OLD_LAST_PASSWORD_CHANGE, 
   @OLD_MDW_ID,
   @OLD_CHG_ID,
   @OLD_CREATED_BY_MODULE,
   @OLD_CREATED_BY_USER_CODE,
   @OLD_CREATED_BY_OS_USER,
   @OLD_CREATED_BY_USER_NAME,
   @OLD_CREATED_ON,
   @OLD_CHANGED_BY_MODULE,
   @OLD_CHANGED_BY_USER_CODE,
   @OLD_CHANGED_BY_OS_USER,
   @OLD_CHANGED_BY_USER_NAME,
   @OLD_CHANGED_ON
WHILE (@@FETCH_STATUS = 0)
   BEGIN
   SET @ChangeID = NEXT VALUE FOR CHANGE_ID_SEQ
   INSERT INTO USERS_LOG
      (
      CHANGE_ID,
      ACTION,
      NEW_OLD,
      CODE, 
      NAME, 
      PASSWORD, 
      GROUP_CODE, 
      ACTIVE, 
      LOCKED, 
      CHANGE_PASSWORD_FLAG, 
      NO_OF_ATTEMPTS, 
      LAST_PASSWORD_CHANGE, 
      MDW_ID,
      CHG_ID,
      CREATED_BY_MODULE,
      CREATED_BY_USER_CODE,
      CREATED_BY_OS_USER,
      CREATED_BY_USER_NAME,
      CREATED_ON,
      CHANGED_BY_MODULE,
      CHANGED_BY_USER_CODE,
      CHANGED_BY_OS_USER,
      CHANGED_BY_USER_NAME,
      CHANGED_ON,
      ACTION_ID,
      CHG_DATE_TIME,
      CHG_USER_ID,
      CHG_MACHINE_NAME,
      CHG_SESSION_ID
      )
   VALUES
      (
      @ChangeID,
      @Action1,
      'OLD',
      @OLD_CODE, 
      @OLD_NAME, 
      @OLD_PASSWORD, 
      @OLD_GROUP_CODE, 
      @OLD_ACTIVE, 
      @OLD_LOCKED, 
      @OLD_CHANGE_PASSWORD_FLAG, 
      @OLD_NO_OF_ATTEMPTS, 
      @OLD_LAST_PASSWORD_CHANGE, 
      @OLD_MDW_ID,
      @OLD_CHG_ID,
      @OLD_CREATED_BY_MODULE,
      @OLD_CREATED_BY_USER_CODE,
      @OLD_CREATED_BY_OS_USER,
      @OLD_CREATED_BY_USER_NAME,
      @OLD_CREATED_ON,
      @OLD_CHANGED_BY_MODULE,
      @OLD_CHANGED_BY_USER_CODE,
      @OLD_CHANGED_BY_OS_USER,
      @OLD_CHANGED_BY_USER_NAME,
      @OLD_CHANGED_ON,
      @ActionID,
      GetDate(),
      @mAppUserCode,
      @mMachine,
      @mSessionID
      )

   FETCH NEXT FROM DeletedCursor INTO
      @OLD_CODE, 
      @OLD_NAME, 
      @OLD_PASSWORD, 
      @OLD_GROUP_CODE, 
      @OLD_ACTIVE, 
      @OLD_LOCKED, 
      @OLD_CHANGE_PASSWORD_FLAG, 
      @OLD_NO_OF_ATTEMPTS, 
      @OLD_LAST_PASSWORD_CHANGE, 
      @OLD_MDW_ID,
      @OLD_CHG_ID,
      @OLD_CREATED_BY_MODULE,
      @OLD_CREATED_BY_USER_CODE,
      @OLD_CREATED_BY_OS_USER,
      @OLD_CREATED_BY_USER_NAME,
      @OLD_CREATED_ON,
      @OLD_CHANGED_BY_MODULE,
      @OLD_CHANGED_BY_USER_CODE,
      @OLD_CHANGED_BY_OS_USER,
      @OLD_CHANGED_BY_USER_NAME,
      @OLD_CHANGED_ON
   END

CLOSE DeletedCursor
CLOSE InsertedCursor
CLOSE UpdatedCursor

DEALLOCATE DeletedCursor
DEALLOCATE InsertedCursor
DEALLOCATE UpdatedCursor

END
GO
/********          *********/

0 个答案:

没有答案