Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Oracle trigger to SQL trigger Expand / Collapse
Author
Message
Posted Tuesday, March 5, 2013 3:29 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, April 20, 2016 6:26 AM
Points: 236, Visits: 487
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
Post #1426691
Posted Tuesday, March 5, 2013 4:44 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:44 AM
Points: 14,189, Visits: 37,099
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!
Post #1426748
Posted Tuesday, March 5, 2013 6:43 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 11:33 AM
Points: 5,097, Visits: 7,458
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 at GMail
Post #1426796
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse