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.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 how to get last inserted record frm table

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?
Go to Top of Page

Arunavally
Yak Posting Veteran

58 Posts

Posted - 2013-11-06 : 05:28:14
How to use OUTPUT clause
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-11-06 : 06:38:32
quote:
Originally posted by Arunavally

How to use OUTPUT clause


see
http://blogs.msdn.com/b/sqltips/archive/2005/06/13/output-clause.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

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/
Go to Top of Page

Arunavally
Yak Posting Veteran

58 Posts

Posted - 2013-11-07 : 02:48:40
Thank you
Go to Top of Page
   

- Advertisement -