我在SQL SERVER中寫了一個觸發器,這個觸發器是對表test的inserted而觸發的,現在我在ERP中對表test進行inserted操作,我的觸發器中用raiserror,有如我所願的提示信息,但不能在ERP中存盤,希望有提示,但可以存盤.請教如何實現?謝謝

解决方案 »

  1.   

    就是只是提示警告,不进行数据回滚.在SQL中如何实现?
      

  2.   

    --示例
    USE pubs
    IF EXISTS (SELECT name FROM sysobjects
          WHERE name = 'employee_insupd' AND type = 'TR')
       DROP TRIGGER employee_insupd
    GO
    CREATE TRIGGER employee_insupd
    ON employee
    FOR INSERT, UPDATE
    AS
    /* Get the range of level for this job type from the jobs table. */
    DECLARE @min_lvl tinyint,
       @max_lvl tinyint,
       @emp_lvl tinyint,
       @job_id smallint
    SELECT @min_lvl = min_lvl, 
       @max_lvl = max_lvl, 
       @emp_lvl = i.job_lvl,
       @job_id = i.job_id
    FROM employee e INNER JOIN inserted i ON e.emp_id = i.emp_id 
       JOIN jobs j ON j.job_id = i.job_id
    IF (@job_id = 1) and (@emp_lvl <> 10) 
    BEGIN
       RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
       ROLLBACK TRANSACTION
    END
    ELSE
    IF NOT (@emp_lvl BETWEEN @min_lvl AND @max_lvl)
    BEGIN
       RAISERROR ('The level for job_id:%d should be between %d and %d.',
          16, 1, @job_id, @min_lvl, @max_lvl)
       ROLLBACK TRANSACTION
    END