Oracle trigger to SQL trigger

  • Hi,

    Got a Oracle script with a trigger in it and I want to have it as a SQL trigger script

    Can anyone help me with this

    CREATE OR REPLACE TRIGGER MESSAGES_INS BEFORE INSERT ON MESSAGES

    FOR EACH ROW

    BEGIN

    IF :NEW.id IS NULL THEN

    SELECT SEQ_MESSAGE_ID.nextval INTO :NEW.id FROM DUAL;

    END IF;

    END;

    /

    ALTER TRIGGER MESSAGES_INS ENABLE;

    Thanks

  • That trigger emulates what a column with an identity does... so you can simply define the column as having an identity and skip the trigger completely.

    Create table tbname (colname int identity(1,1) not null.........

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Lowell (3/5/2013)


    That trigger emulates what a column with an identity does... so you can simply define the column as having an identity and skip the trigger completely.

    Create table tbname (colname int identity(1,1) not null.........

    Given that this is a SQL 2012 forum, the OP can also use the new SEQUENCE object, which could be the only feature that gives the exact same implementation. The Oracle sequence could well be something other than int from 1 to N increment by 1.

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply