Click here to Skip to main content
Rate this: bad
good
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 10:16am
RedDk10.3K
Edited 18-Jan-13 11:01am
v2
Rate this: bad
good
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.
  Permalink  
Rate this: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 Kornfeld Eliyahu Peter 275
1 Maciej Los 214
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 163
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2014
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