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 3755808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:45:19+00:00 2026-05-19T09:45:19+00:00

Table Event has one instead of trigger, whos purpose is to generate primary key

  • 0

Table Event has one instead of trigger, whos purpose is to generate primary key EventId as Max+1, rest of the columns are populated from inserted.

EventId is not Identity, and we can’t make it identity as there is lots of depedency there, Trigger logic:

SELECT TOP 1 @ID = Event.EventID FROM Event
IF (@ID IS NULL)
BEGIN
  SET @ID=1
END
ELSE
BEGIN
  SELECT @ID = MAX(Event.EventID) FROM Event
  SET @ID=@ID+1
END
--Then just a insert statment with this id as EventId and rest of the columns from inserted table

Now sometimes when i tries to insert into this table, it still says can’t insert duplicate in eventId, Not sure why this is happning…

Looks like trigger is not fireing in some case? Why

  • 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-19T09:45:19+00:00Added an answer on May 19, 2026 at 9:45 am

    You’re probably assuming that there’s a single row in the inserted pseudo table, and failing when a multi-row insert occurs.

    You want something like:

    ;with maxID as (
        select MAX(EventID) as EventID from Event
    ), nrows as (
        select
            ROW_NUMBER() OVER (ORDER BY newid()) +
                COALESCE((select EventID from maxID),0) as EventID,
            /* columns from inserted table */
        from inserted
    )
    insert into Event (EventID,/* other columns */)
    select EventID,/* other columns */
    from nrows
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Oracle table which contains event log messages for an application. We
Using jQuery, how do you bind a click event to a table cell (below,
I have 2 tables event + event_artist event eventId | eventName ------------------- 1 ,
Instead of a silent program, or one with a console, I wanted to make
I have the following data model: Camp -> CampEvent <- Event. Camp has CampId
I have a table of events with a recorded start and end time as
I have a table of events, I need to find all tail events of
I have an Events table whose goal is to store actions done by web
Sql Server Management Studio 2008 is not scripting table permissions even when I select
How come the Table classes Generated in the Dbml do not contain useful events

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.