I’m not familiar with MSSQL triggers I need to convert a Oracle trigger in to MSSQL
here’s the Oracle trigger:-
create or replace trigger TRG_GRP_SEQ
before insert on T_USER_GROUP
for each row
begin
select count(*) into :new.GROUPSEQUENCE from T_USER_GROUP;
end;
I’m in trouble covering the before statements and for each need some helping hand.
Description: This trigger does is before inserting each row in to the table T_USER_GROUP the GROUPSEQUENCE will increment by one value determining the total count (just like ID generation)
Thanks.
SQL Server can make columns
identitywhich means they autoincrement for newly inserted rows. I recommend you use one, which would let you dispense with the trigger entirely.If you already have data in your table, then you’ll ned to create a new table and populate it like so:
Now you can completely skip the GroupSequence column when inserting, and it will always get the next, incremented value. You can learn this value immediately after like so: