By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,474 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,474 IT Pros & Developers. It's quick & easy.

how to delete last inserted row in sql server

P: 1
how to delete last inserted row in sql server
Sep 4 '14 #1
Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,430
You would need an auto increment field or a date field that defaults to when the row is inserted.
Sep 4 '14 #2

P: 9
delete top 1 from <table>.
Sep 10 '14 #3

Rabbit
Expert Mod 10K+
P: 12,430
Mukherjee, your code will not work.
Sep 10 '14 #4

twinnyfo
Expert Mod 2.5K+
P: 3,482
sumit anand,

You would need a way to know which record was the last inserted. Rabbit's suggestion of an auto-increment field will tell you the most recent, based on the record with the largest value.

@mukherjee, your method willonly delete the first record the query finds, which could be just about any record, depending upon how the query is written.
Sep 10 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.