SQL Server: How to get the Last Inserted Identity value. What is the fastest way?
Hello friends, Very often after inserting a row in a table it is necessary to know what is the id of the row just inserted. We have various methods but what is the fastest? Today we take a watch to this question! Enjoy the reading! As usually for maximum clarity we will proceed with an example using our standard table. It has an identity column called ID The classic way! SELECT MAX ( ID ) FROM ORDTES (1 riga interessata) Tabella 'OrdTes'. Conteggio analisi 1, letture logiche 2, letture fisiche 0, letture read-ahead 0, letture logiche LOB 0, letture fisiche LOB 0, letture read-ahead LOB 0. (1 riga interessata) SELECT TOP 1 ID FROM ORDTES ORDER BY ID DESC (1 riga interessata) Tabella 'OrdTes'. Conteggio analisi 1, letture logiche 2, letture fisiche 0, letture read-ahead 0, letture logiche LOB 0, letture fisiche LOB 0, letture read-ahead LOB 0. We can note that with these f...