x
login about faq Site discussion (meta-askssc)

How to fetch last inserted row

Hi, can anyone let me know how to fetch/get last inserted row in sql server. Table have NO Primary key, Identity, it has only one column 'Employee Name'.

more ▼

asked Apr 23 '10 at 09:11 AM in Default

Vijay 3 gravatar image

Vijay 3
11 1 1

(comments are locked)
10|1200 characters needed characters left

2 answers: sort oldest

You can't get it as there is no way to tell it was the last inserted, either add a primary key or a date added field.

more ▼

answered Apr 26 '10 at 05:33 AM

RickD gravatar image

RickD
1.6k 1 1 4

(comments are locked)
10|1200 characters needed characters left

You can not fetch data while there is no primary key you should add one primary key or date time field.

more ▼

answered Apr 26 '10 at 08:37 AM

Gaurav 1 gravatar image

Gaurav 1
2

Yes you can fetch data, you just can't guarantee the order of that data if you are looking for it in this way. You can order it however you want, by checksum(), alphabetically etc.. You just can't tell when it was added to the table.

Apr 26 '10 at 10:44 AM RickD
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x454

asked: Apr 23 '10 at 09:11 AM

Seen: 438 times

Last Updated: Apr 23 '10 at 09:11 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.