portal entry

select a category, or use search below
(searches all categories and all time range)

TSQL – Getting New Primary Key

| View in Portal
January 02, 2019 12:24:39 AM GMT
<p>There are so many ways to getting a Primary Key from a table right after an INSERT, which should you use? Trick question. You get it when you do the INSERT, not after.   Resources https://stackoverflow.com/questions/1360453/how-do-i-insert-into-a-table-and-get-back-the-primary-key-value https://github.com/jmohler1970/TSQL_gettingPK</p>
<p>The post <a rel="nofollow" href="https://coldfusion.adobe.com/2019/01/tsql-getting-new-primary-key/">TSQL – Getting New Primary Key</a> appeared first on <a rel="nofollow" href="https://coldfusion.adobe.com">ColdFusion</a>.</p>
Labels: Blog, Learning, blog, Data, insert, learning


How about using <cfquery name="myQuery" result="myQuery_Result"> and then calling #myQuery_Result.generatedKey#?
Comment by David Byers
1528 | January 08, 2019 09:44:02 PM GMT
I tried to see if I could get to work. I made a query, but that field is not available in my result. It does not seem to be universally available. <a href="https://stackoverflow.com/questions/40270744/the-generatedkey-value-is-missing-from-my-cfquery-result-structure" rel="nofollow">https://stackoverflow.com/questions/40270744/the-generatedkey-value-is-missing-from-my-cfquery-result-structure</a> If it would have worked, I would have ran SELECT top 100 deqs.last_execution_time AS [Time], dest.TEXT AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest ORDER BY deqs.last_execution_time DESC To see what query it did to get the results ~~~~ If someone gets this to work, I would like to know what it does.              
Comment by James Mohler
1529 | January 09, 2019 06:10:37 PM GMT
Interesting! I've never experienced a problem getting the generatedKey to appear in the results, but apparently it can happen.  I've just never run across it.
Comment by David Byers
1541 | January 15, 2019 08:32:31 PM GMT