aspnet_Users 表的排序顺序

发布于 2024-08-24 01:22:33 字数 1037 浏览 3 评论 0原文

我想知道 aspnet_Users 表是否始终按用户名排序,即使我添加了按字母顺序排列在两个现有用户之间的新用户。

我注意到方法 Membership.GetAllUsers() 似乎总是返回一个排序的 MembershipUsers 集合。

另外,当我查看 SQL Server Management Studio 并运行一个没有 ORDERBY 子句的简单 SQL 查询时

SELECT [UserName]
  FROM [MyDb].[dbo].[aspnet_Users]

......我总是得到一个排序结果列表。

我对 SQL Server 仍然很不熟悉,但我预计当我向表中添加新行时,它会(物理上)附加到表的末尾。当我运行不带 ORDERBY 的 select 语句时,将按照最初插入数据库的顺序选择行(因此没有任何特定的排序顺序)。

我想我错了。但它到底是如何运作的呢? aspnet_Users 表可能有什么特别之处吗?

我很高兴 GetAllUsers() 返回的 MemberShipUserCollection 已排序,但它总是能保证吗?

感谢您提供信息!

更新

我刚刚注意到数据库包含一个名为 aspnet_Membership_GetAllUsers 的存储过程。该过程实际上包含 UserNameORDER BY 子句。因此,如果当我在代码中使用 Membership.GetAllUsers() 时确实总是调用此存储过程(至少如果我使用 SqlMembershipProvider),则它解释了为什么 Membership.GetAllUsers 返回的集合() 按用户名排序。

仍然存在的问题:Membership.GetAllUsers() 实际上是基于此存储过程吗?

I am wondering if the aspnet_Users table is always sorted (by UserName) even if I add new users which are alphabetically between two already existing users.

I've noticed that the method Membership.GetAllUsers() always seems to return a sorted collection of MembershipUsers.

Also when I look into SQL Server Management Studio and run a simple SQL query without ORDERBY clause...

SELECT [UserName]
  FROM [MyDb].[dbo].[aspnet_Users]

...I get always a sorted result list.

I'm still very unfamiliar with SQL Server but I expected that when I add a new row to a table it is (physically) appended to the end of the table. And when I run a select statement without ORDERBY the rows will be selected in the order they were initially inserted into the database (so without any specific sort order).

I am wrong I guess. But how does it really work? Is it perhaps something special with the aspnet_Users table?

I am happy that the MemberShipUserCollection returned by GetAllUsers() is sorted but is it always guaranteed?

Thanks for info!

Update

I've just noticed that the database contains a stored procedure called aspnet_Membership_GetAllUsers. This procedure actually contains an ORDER BY clause by UserName. So if this stored procedure is indeed always called when I use Membership.GetAllUsers() in my code (at least if I am using the SqlMembershipProvider) it explains why the collection returned by Membership.GetAllUsers() is sorted by UserName.

Remains the question: Is Membership.GetAllUsers() actually based on this stored procedure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只为守护你 2024-08-31 01:22:33

UserName 上可能有聚集索引。这意味着表中的行按用户名顺序存储。 SQL Server 通常(但并非总是)按照它使用的索引的顺序返回行。

如果没有order by,就没有任何保证。因此,如果您依赖于排序的结果,请不要忘记 order by :)

There might be a clustered index on UserName. That means the rows in the table are stored in UserName order. SQL Server will usually (but not always) return rows in the order of the index it uses.

Without order by, there are no guarantees. So if you rely on the results being ordered, don't forget the order by :)

琉璃繁缕 2024-08-31 01:22:33

UserName 和 ApplicationID 上有一个聚集索引。由于您通常只使用 1 个 applicationID,因此它看起来是按 UserName 排序的。表中的数据按其聚集索引排序。这意味着您通常会看到未排序的日期按聚集列的顺序返回。然而,这永远无法保证。因此,如果您希望结果按特定顺序返回,则必须使用 ORDER BY。每当您将数据插入到具有聚集索引的表中时,它都会将其插入到表中物理所属的位置。研究分页和集群与非集群。它将帮助您了解 SQL Server 如何存储数据。看看这个http://en.wikipedia.org/wiki/Clustered_index#Architecture以获得概述。

There is a clustered Index on UserName and ApplicationID. Since you usually only use 1 applicationID then it will appear to be sorted by UserName. Data in tables are ordered by their clustered index. Which means you will usually see unsorted date return in the order of the clustered columns. However, it is NEVER guaranteed. So you must use an ORDER BY if you want the results to come back in a specific order. Any time you insert data into a table with a Clustered Index it will insert it into the table wherever if physically belongs. Look into paging and clustered vs non clustered. It will help you understand how SQL Server stores data. Look at this http://en.wikipedia.org/wiki/Clustered_index#Architecture for an overview.

淡墨 2024-08-31 01:22:33

如果没有显式在 SQL 中指定 ORDER BY 子句,任何顺序都是偶然的,并且绝对不能以任何方式、形式或形式得到保证。不要依赖它。

如果您需要特定顺序,请使用 ORDER BY 定义该顺序。

Without explicitly specifying an ORDER BY clause in your SQL, any order is accidental and definitely not guaranteed in any way, shape or form. Don't rely on it.

If you need a specific order, use ORDER BY to define that order.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文