• If there would be the same identity generated an error would happen on insert to SESSION table.

    Because of a primary or unique key on the IDENTITY column in table SESSION.

    Oh, wait a minute - it probably does happen!

    How do you know the insert has succeeded?

    Do you handle errors in your code?

    No, you don't.

    So, if the insert into SESSION fails then the next insert into _LOG_SESSION will use @gdGUID which never got inserted into SESSION and the SCOPE_IDENTITY() from the previous IDENTITY insert.

    Can you fund duplicate entries in identity column in table SESSION?

    _____________
    Code for TallyGenerator