Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5993293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:39:16+00:00 2026-05-22T23:39:16+00:00

I’m not familiar with MSSQL triggers I need to convert a Oracle trigger in

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:39:17+00:00Added an answer on May 22, 2026 at 11:39 pm

    SQL Server can make columns identity which 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:

    CREATE TABLE T_USER_GROUP_New (
       GroupSequence int identity(1,1) NOT NULL,
       <Other Columns ...>
    );
    
    SET IDENTITY_INSERT T_USER_GROUP_New ON;
    INSERT T_USER_GROUP_New (GroupSequence, <OtherColumns ...>)
    SELECT * FROM T_USER_GROUP;
    SET IDENTITY_INSERT T_USER_GROUP_New OFF;
    
    -- Add script here to drop FK constraints from any tables with an FK to T_USER_GROUP
    
    EXEC sp_rename 'T_USER_GROUP', 'T_USER_GROUP_Old';
    EXEC sp_rename 'T_USER_GROUP_New', 'T_USER_GROUP';
    
    -- Add script here to recreate FK constraints from any tables with an FK to T_USER_GROUP
    
    -- Add script here to add appropriate indexes and constraints to T_USER_GROUP
    -- and rename or drop them from T_USER_GROUP_Old
    

    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:

    DECLARE @NewGroupSequenceStart int,
       @NewGroupSequenceEnd int;
    
    INSERT T_USER_GROUP (<Columns not including GroupSequence ...>)
    VALUES (<Values ...>);
    -- or SELECT <Columns ...> FROM Somewhere
    
    SELECT @NewGroupSequenceStart = Scope_Identity(), @NewGroupSequenceEnd = @@RowCount;
    SET @NewGroupSequenceEnd = @NewGroupSequenceEnd + @NewGroupSequenceStart - 1;
    
    -- Now these two variables have the start and end GroupSequence IDs
    -- that were newly generated (you can insert multiple rows).
    -- This could probably be cleaned up a little but I don't have time to test now.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.