Click here to Skip to main content
13,451,455 members (45,376 online)
Rate this:
Please Sign up or sign in to vote.
Like using INSERT INTO does by appending data to the end of a table?
UPDATE [db].[schm].[table] SET [col] = 'new data' WHERE [idx] = 1 

Overwrites. There must be a singularly simple way to go about doing this using TSQL.
Posted 18-Jan-13 9:16am
Updated 18-Jan-13 10:01am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

No, there isn't.

The order of records stored in SQL server (and pretty much all other databases) is solely up to SQL server - you cannot influence it in any way as the data is physically stored in the way which is most efficient for the particular version of SQL, the indexes the data needs, and the data itself. Similarly, unless you tell it otherwise, SQL server is at liberty to return rows in any order it finds suitable - not the order you entered them chronologically, not the order you last got them, but any order it wants.

You can specify what order the records are returned in any time you use a SELECT statement - just add an ORDER BY clause[^] and SQL will return rows ordered exactly the way you ask, and will return the same order records every time until you add, remove or change row data. But you can't affect the order they are stored in, in the slightest.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Just figured it out ...
1. Create another table like first table
2. Use INSERT INTO ... VALUES without [idx], just [col] ...
3. SELECT [col] FROM [db].[schm].[table] ORDER BY [idx] DESC
4. INSERT INTO again appending the "first row" [col] to the end (notice idx is intact order)
5. Do the whole above steps over reversing the contents [idx] wise.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.180318.3 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100