sqlsqliteinsertrowprimary-key

Inserting a row and returning its primary key


I have inserted a row in a table. How do I "SELECT" the primary key of the row just inserted?


Solution

  • For MS SQL Server:

    SCOPE_IDENTITY() will return you the last generated identity value within your current scope:

    SELECT SCOPE_IDENTITY() AS NewID