1

I'm trying to quickly edit the 10 most recent rows in a large table.

I've been using SQL Server Object Explorer to "Edit all rows" which gives me every row in the table. I scroll to the bottom after it finally displays the results, and I can click on a cell and modify it then and there.

Rather than load the entire table I thought that just getting the 10 latest rows would be quicker. Using DESC alone isn't an option as I need the results ASC while being the most recent 10. A helpful answer in another thread recommended creating a new query with this-

WITH bottom AS (
SELECT        TOP (10) *
FROM            tbl
ORDER BY n DESC
)
SELECT        *
FROM            bottom
ORDER BY n 

This is awesome, and give me the exact data I want. The only problem is that the cells appear to be read-only. Is there any way of updating these cells without UPDATE statements? Maybe a way to switch to an "Edit" rows mode?

I have a very limited knowledge of SQL, so maybe I'm going about this the wrong way. Any answers or suggestions would be greatly appreciated.

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 3
    I don't quite understand why you wrote your SQL statement the way you did. Doesn't ORDER BY ID DESC already get you the most recent records at the top of the list? If you want a genuine GUI that only displays the actual records that you want in the correct order, you need to write one; the Object Explorer is a blunt instrument. – Robert Harvey Jan 22 '14 at 01:34
  • Yes it does, however in a table where the id's go (1,2,3,4,5,6,7,8,9) ORDER BY id DESC gives me (9,8,7) while I'm looking for (7,8,9). It seems trivial, but in the particular instance the records are fairly confusing when not in ASC order. I believe you hit the nail on the head with your blunt instrument comment, and without the knowledge of how to write my own GUI I'll probably keep doing it as I have been. It's just hard to accept when I can "See it right there" and not edit it. Thanks. – user3221491 Jan 22 '14 at 02:09
  • why you are using `CTES?` why not jus `select top 10 * from table order by id desc` ? – vhadalgi Jan 22 '14 at 06:19

0 Answers0