x

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 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.7k 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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

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

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x472

asked: Apr 23 '10 at 09:11 AM

Seen: 873 times

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