MS SQL Server Last Inserted ID

后端 未结 7 1000
一个人的身影
一个人的身影 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:03

    Dear friend you have to select id of last record inserted and then pass it in another table so bellow code will help you very well

    Insert INTO TABLE_ID (Table_NAME), Values (Table_Products)
    DECLARE @ID int;
    set @ID = SCOPE_IDENTITY(); 
    
    Insert INTO Table_Products (ID, Product_Name) 
    Values (@ID, SomeProduct)
    

    this code will solve your problem i define @ID for your last record id and then insert it in your other table

提交回复
热议问题