Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 18-Jan-13 10:01am
v2

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.
 
Share this answer
 
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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900