MS SQL Server Last Inserted ID

后端 未结 7 1004
一个人的身影
一个人的身影 2020-12-11 03:16

In my database all tables are using a common table for Sequence(ID_Table).

TABLE_ID has two fields (Common_ID, Table_Name).

If I insert any record in the tab

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 04:00

    All the other answers so far declare intermediary variables for SCOPE_IDENTITY(), but it could be simpler:

    INSERT INTO dbo.TABLE_ID (Table_NAME) VALUES 'Table_Products';
    
    INSERT INTO dbo.Table_Products (ID, Product_Name) VALUES (SCOPE_IDENTITY(),'SomeProduct');
    

提交回复
热议问题