Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Arunavally
Yak Posting Veteran
58 Posts |
Posted - 2013-10-31 : 08:00:12
|
Hai, How to get last inserted record from table without id desc option.Kindly help me. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-10-31 : 08:21:00
|
quote: Originally posted by Arunavally Hai, How to get last inserted record from table without id desc option.Kindly help me.
Several possibilities, depending on your situation.1. You can use the OUTPUT clause when you insert the data - which will give you the data that was inserted.2. If you have an ever-increasing key or a datestamp column, you can use MAX to get the latest record.3. If there is an identity column in the table, you can use SCOPE_IDENTITY function to get the last value inserted (immediately after the insert).Is there any performance or other issue in using hte DESC option? |
|
|
Arunavally
Yak Posting Veteran
58 Posts |
Posted - 2013-11-06 : 05:28:14
|
How to use OUTPUT clause |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-11-06 : 07:50:58
|
A good description of output clause with examples can be found here: https://www.simple-talk.com/sql/learn-sql-server/implementing-the-output-clause-in-sql-server-2008/ |
|
|
Arunavally
Yak Posting Veteran
58 Posts |
Posted - 2013-11-07 : 02:48:40
|
Thank you |
|
|
|
|
|