查询按日期时间排序后如何更新SQL Server表 [英] How to update SQL Server Table after query sort by datetime

查看:373
本文介绍了查询按日期时间排序后如何更新SQL Server表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SQL Server数据库,并且具有 datetime 列,数据类型为 datetime ,现在我已经知道如何按日期时间对表进行排序:

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]; 

结果:

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.

任何人都可以帮忙吗?

推荐答案


我要保留或按日期时间对数据进行排序。

I want to keep or the data sort by datetime.

您可以没错SQL表表示无序行集,因此您实际上不能对存储的数据进行排序。没有可以修改的固有或默认数据顺序。

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.

每当需要按给定顺序检索数据时,确实需要使用 order by 子句。否则,顺序为 undefined ,这意味着数据库可以自由按其喜欢的任何顺序返回行。

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.

这篇关于查询按日期时间排序后如何更新SQL Server表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆