SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 how to get last inserted record frm table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Arunavally
Yak Posting Veteran

India
58 Posts

Posted - 10/31/2013 :  08:00:12  Show Profile  Reply with Quote
Hai, How to get last inserted record from table without id desc option.
Kindly help me.

James K
Flowing Fount of Yak Knowledge

3704 Posts

Posted - 10/31/2013 :  08:21:00  Show Profile  Reply with Quote
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

India
58 Posts

Posted - 11/06/2013 :  05:28:14  Show Profile  Reply with Quote
How to use OUTPUT clause
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 11/06/2013 :  06:38:32  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3704 Posts

Posted - 11/06/2013 :  07:50:58  Show Profile  Reply with Quote
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

India
58 Posts

Posted - 11/07/2013 :  02:48:40  Show Profile  Reply with Quote
Thank you
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000