当我创建一个与 Access 中的其他查询配合使用的查询时,幕后发生了什么?
如果我在 Microsoft Access 中有几个查询,然后在另一个新查询中使用,则 Access 是否独立运行每个包含的查询,然后将这些结果用作新查询中的新表,或者是否尝试合并所有查询将子查询转换为新的单个查询?
例如,假设我有一个返回teacherID 和teacherName 的查询,那么我还有另一个返回studentID、teacherID 和studentName 的查询。然后,我尝试在一个新查询中一起使用这两个查询,该查询执行类似以下操作:
SELECT qryTeacher.teacherName, qryStudent.studentName
FROM qryTeacher INNER JOIN qryStudent
WHERE qryStudent.teacherID=qryTeacher.teacherID;
这会执行 qryTeacher 查询和 qryStudent 查询,然后对结果运行此查询,还是会尝试使用所有三个查询构建一些新查询?
另外,源是链接的 SQL 表还是访问 .mdb 源有什么关系吗?
If I have a couple of queries in Microsoft Access that I then use in another new query, does access independently run each of the contained queries and then use those results as the new tables in the new query, or does it try to merge all of the subqueries into a new single query?
For example, say I have a query that returns a teacherID and a teacherName, then I have another query that returns a studentID, teacherID, and a studentName. Then I try to use both of these queries together in a new query that does something like
SELECT qryTeacher.teacherName, qryStudent.studentName
FROM qryTeacher INNER JOIN qryStudent
WHERE qryStudent.teacherID=qryTeacher.teacherID;
Would this execute the qryTeacher query and the qryStudent query and then run this query on the results, or would it try to build some new query using all three queries?
Also, does it matter if the source is a linked SQL table vs an access .mdb source?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想了解数据库引擎如何处理查询的详细信息,请在网上搜索“Jet ShowPlan”。
这一切都在“幕后”变得相当复杂。即使相同的查询也可能不会连续两次以相同的方式执行。例如,利用新的更新的索引统计数据,查询规划器可以识别更有效的路线来检索所请求的数据。
更直接地回答您的问题......如果您创建一个从其他两个查询中提取数据的查询,请不要假设这两个查询在组合或馈送到第三个查询之前是单独执行的。事情可能会这样发生。但优化器会判断什么是检索数据最有效的方法,并根据需要重新组织查询计划。
If you want to know the details of how the database engine handles your queries, search the net for "Jet ShowPlan".
It all gets quite complex "under the hood". And even the same query may not be executed the same way twice in a row. For example, with new updated index statistics, the query planner may identify a more efficient route to retrieve the requested data.
More directly to the point of your question ... if you create a query which pulls data from two other queries, do not assume those two are executed separately before being combined or fed to the third. It could happen that way. But the optimizer will make judgments about what it considers to be the most efficient way to retrieve the data, and will re-organize the query plan as it sees fit.