How to update SQL Server Table after query sort by datetime

帅比萌擦擦* 提交于 2020-04-18 03:46:40

问题


I'm using a SQL Server database and I have a datetime column, datatype is datetime, now I already know how to sort table by datetime:

SELECT *
FROM [database].[dbo].[data]
ORDER BY [datetime]; 

Result:

datetime
2020-03-18 09:18:00
2020-03-18 09:19:00
2020-03-18 09:20:00
2020-03-18 09:21:00
.............
.............
.............

My question is after the above step that query sort it by datetime, how can I update and save the table? Because I want to keep or the data sort by datetime.

Can anyone help?


回答1:


I want to keep or the data sort by datetime.

You just can't. SQL tables represent unordered sets of rows, so you cannot actually order the stored data. There is no inherent or default data ordering that you could modify.

You might notice that rows appear to be returned in the same order when you run the same query again, but database engines do not whatsoever guarantee that, and the results you see today may change in the future.

Whenever you need to retrieve the data in a given order, you do need to use an order by clause. Otherwise, the ordering is undefined, meaning that the database is free to return the rows in any order it likes.



来源:https://stackoverflow.com/questions/60874482/how-to-update-sql-server-table-after-query-sort-by-datetime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!