Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 22nd, 2006, 01:36 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old November 22nd, 2006, 08:40 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
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
Reply With Quote
  #3 (permalink)  
Old November 22nd, 2006, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Hudson, MA, USA.
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.
je.mason@comcast.net
Reply With Quote
  #4 (permalink)  
Old November 22nd, 2006, 10:27 AM
Friend of Wrox
Points: 1,536, Level: 15
Points: 1,536, Level: 15 Points: 1,536, Level: 15 Points: 1,536, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2006
Location: , MI, USA.
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
Reply With Quote
  #5 (permalink)  
Old November 23rd, 2006, 07:50 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:09 AM.


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