March 5, 2013 at 3:29 am
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
March 5, 2013 at 4:44 am
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
March 5, 2013 at 6:43 am
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