79372551

Date: 2025-01-20 20:20:40
Score: 1
Natty:
Report link

when you create your table, define your auto incrementing column with a type of INT IDENTITY(1,1) that means that it starts at 1 and increments by 1. You do not need to specify the column during the INSERT.

CREATE TABLE TEST_TABLE(
   ID INT NOT NULL IDENTITY(1,1) 
   ...
 )

After inserting you can call a SQL function named SCOPE_IDENTITY() and it will return to you the last integer assigned using the current connection.

What is the difference between Scope_Identity(), Identity(), @@Identity, and Ident_Current()?

Reasons:
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Starts with a question (0.5): when you
  • Looks like a comment (1):
  • High reputation (-2):
Posted by: T McKeown