Using SQL Server and tables with identity fields (auto increment primary keys)? Then you have probably needed to know that assigned id and have resorted to using follow-up queries (probably within a transaction block). Well, here’s a much simpler (as well as safer) solution. Create a trigger on the table containing the code “SELECT @@IDENTITY AS id”. Now every time you do an INSERT operation the INSERT query will return a single row containing a single column called id which will contain the newly assigned id. (Applies to: ColdFusion All)

Leave a Reply