Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 22nd, 2006, 01:36 AM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default How can I get the last inserted rows?

Hi everybody..

I'm in a situation to get the last inserted rows from a table in sql server 2000. The table doesn't contains any identity or timestamp columns. I cannot able to include any addiional fields to this table.

I'm very much thankful with the hope any one suggest the solution.

with regards
Fraijo
 
Old November 22nd, 2006, 08:40 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

You already have them... you just inserted them... store the primary key in the app before you insert them into a table. If, for some reason, that's just not working for you... you'll need to insert them into an empty table first (to remember what they are) and then into the final table.

Another way is to make a trigger on the table that will return the rows just inserted. That actually might be the easiest way... don't forget to SET NOCOUNT ON...

--Jeff Moden
 
Old November 22nd, 2006, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Perhaps he could add an INSERT trigger to the table in question and record appropriate information elsewhere about the row(s) being inserted.

I'm having trouble resisting launching off onto my rant about the concept of "last" when applied to a table in a relational database. Without some sort of information on which to order the row so the concept of "last" has some meaning, the OP has a real problem.

A trigger could store the current_timestamp when the row was inserted. Ordering on that would allow "last" to have a meaning.

Jeff Mason
Custom Apps, Inc.
[email protected]
 
Old November 22nd, 2006, 10:27 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

 (We must've crossed postings when I had an ephipany about the trigger like you did).

Yep... that's one of my favorite rant's as well. However, I think that in this case, the requester means "the last group of records the current session just inserted"...

--Jeff Moden
 
Old November 23rd, 2006, 07:50 AM
Registered User
 
Join Date: Oct 2006
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Jeff Moden/Jeff Mason

I used a Datatable to insert the rows when I'm inserting the sql table (using c#, ASP.NET) so it clears my problem..

Thanks a lot for your support...

With Regards
Fraijo





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get last inserted record in a table?? dayaananthanm SQL Server 2005 6 June 11th, 2007 09:15 PM
Inserted Identities hossrad SQL Server 2005 1 May 21st, 2007 09:48 AM
Record is Inserted Twice donevco Access 1 February 27th, 2007 12:28 PM
Data to be inserted into the database countmedream BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 November 2nd, 2004 03:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.