为什么压缩 Access 2000 数据库会改变表中记录的顺序?
正如问题所说。 该表没有定义主键。 数据库中的其他表在压缩后不会发生变化,也没有定义主键。
As the question says. The table has no primary key defined. Other tables in the database do not change after compacting, and have as well no primary key defined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“如果表中存在主键,压缩会将表记录重新存储为其主键顺序。这提供了与非维护聚集索引等效的功能,并使 Microsoft Jet 数据库引擎的预读功能更加高效。 ”
ACC2000:碎片整理和压缩数据库以提高性能
“新的压缩方法。现在压缩数据库结果虽然在下一次压缩之前不会维护聚集索引,但这与 Microsoft Jet 2.x 不同,在 Microsoft Jet 2.x 中,数据行按照输入的方式进行存储。新的聚集键压缩方法基于表的主键,输入的新数据将按时间顺序排列。”
Microsoft Jet Version 3.0 中的新功能
这两篇文章都没有告诉您必须遵守的内容:如果
NOT NULL
列上存在UNIQUE
约束(或唯一索引),则将使用该约束来代替PRIMARY KEY
。 我无法确定的是,如果表上有多个UNIQUE
约束:首先创建的约束,ACE/Jet 如何选择一个约束? 第一列的序数位置? 第一个NOT NULL
列的序号位置? 你的猜测和我的一样好。"If a primary key exists in the table, compacting re-stores table records into their Primary Key order. This provides the equivalent of Non-maintained Clustered Indexes, and makes the read-ahead capabilities of the Microsoft Jet database engine much more efficient."
ACC2000: Defragment and Compact Database to Improve Performance
"New compacting method. Compacting the database now results in the indices being stored in a clustered-index format. While the clustered index isn't maintained until the next compact, performance is still improved. This differs from Microsoft Jet 2.x where rows of data were stored the way they were entered. The new clustered-key compact method is based on the primary key of the table. New data entered will be in time order."
New Features in Microsoft Jet Version 3.0
What neither of these articles tells you is something that must be observed: that if a
UNIQUE
constraint (or unique index) exists onNOT NULL
columns then this will be used in lieu of thePRIMARY KEY
. What I haven't been able to ascertain is how ACE/Jet picks one if there are multipleUNIQUE
constraints on the table: first created? first column's ordinal position? firstNOT NULL
column's ordinal position? Your guess is as good as mine.表格没有顺序。 表数据表可以,但那不是表,而是用于显示表的 UI 对象。
如果要控制表的顺序,请使用带有 ORDER BY 子句的 SQL 语句。
您不应该在应用程序中使用表视图。
如果您没有应用程序并且不喜欢默认顺序,请在表数据表上设置 ORDER BY 属性并保存它,或者使用您喜欢的顺序编写查询。
但您需要放弃表格有任何顺序的想法。 这个想法与 SQL 和集合论的基础知识完全矛盾。 您不应该关心记录在物理数据库中实际存储的顺序。
Tables don't have order. A table datasheet may, but that's not the table, but a UI object used to display the table.
If you want to control the order of your table, use a SQL statement with an ORDER BY clause.
You shouldn't be using table view in an application.
If you don't have an application and you don't like the default order, set the ORDER BY property on the table datasheet and save it, or write a query with the order you like.
But you need to give up the idea that tables have any order at all. The mere idea is completely contradictory of the basics of SQL and set theory. You shouldn't care what order the records are actually stored in the physical database.
如果没有主键,Access 可以根据需要随意重新排列表的行。 我的猜测是,效果取决于表的使用模式。 当您删除一行时,数据库只是将其标记为已删除。 压缩时,它通过用未删除的行覆盖已删除的行来回收空间。 如果表有主键,那么数据库将在此过程中小心地保留行顺序(因此这是一个昂贵得多的操作); 否则,就不会。
Without a primary key, Access is free to rearrange the rows of a table as it sees fit. My guess is that the effect depends on the usage pattern for the the table. When you delete a row, the database simply marks it as deleted. When you compact, it reclaims the space by overwriting deleted rows with a non-deleted rows. If a table has a primary key, then the database will be careful to preserve the row ordering during this process (which is consequently a much more expensive operation); otherwise, it won't.