Get table ID after insert with ColdFusion and MySQL

前端 未结 5 459
遥遥无期
遥遥无期 2021-01-04 02:33

My normal process for inserting into one table and then getting the ID back so that I can insert into another table is like this in MSSQL:

DECLARE @transacti         


        
5条回答
  •  醉酒成梦
    2021-01-04 03:10

    As per the answer of @aaron-greenlee, The result variable of INSERT queries contains a key-value pair that is the automatically generated ID of the inserted row; this is available only for databases that support this feature.

    And the below is possible way to return the inserted record for all databases.

    
       INSERT INTO myTable (
          title
       )
       OUTPUT INSERTED.*
       VALUES (
       
       )
    
    

    You will get the inserted record details in result.

    Hope this helps. Thanks.

提交回复
热议问题