问题
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