[英]What does the data in MSysQueries mean?
I've been using VBA to examine all the queries, forms, and modules in my Access 2000 database, but it can be quite tedious and slow. 我一直在使用VBA来检查我的Access 2000数据库中的所有查询,表单和模块,但它可能非常繁琐和缓慢。 Recently, I decided to take a closer look at the system tables in Access, in particular, MSysQueries and MSysObjects.
最近,我决定仔细研究Access中的系统表,特别是MSysQueries和MSysObjects。 Can I use these tables to examine my objects in the database faster?
我可以使用这些表来更快地检查数据库中的对象吗? Of course, these tables are read-only, so I can't make any modifications to the database through them without returning to VBA.
当然,这些表是只读的,所以我不能通过它们对数据库进行任何修改而不返回VBA。 What do the attributes in MSysQueries mean?
MSysQueries中的属性是什么意思?
Well, I came across this post on Google groups. 好吧,我在谷歌小组上发过这篇文章 。 I did further investigation on my own tables and wanted to share a table of information that I created inspired by work already done.
我在自己的桌子上做了进一步的调查,想要分享一个我已经完成的工作所激发的信息表。
Each query can take up multiple rows in the table. 每个查询都可以占用表中的多行。
The row with attribute 0 is the beginning of the query. 具有属性0的行是查询的开头。
The row with attribute 1 indicates the type of the query. 具有属性1的行指示查询的类型。
The rows with attribute 2 (there could be multiple) are each formal parameter of the query. 具有属性2的行(可能有多个)是查询的每个形式参数。 The Flag column indicates the data type (ie "10" for dbText) and the Name1 column indicates the name of the parameter.
Flag列指示数据类型(即dbText的“10”),Name1列指示参数的名称。 If there are no rows with attribute 2, then the query does not have formal parameters.
如果没有属性为2的行,则查询没有形式参数。
The row with attribute 3 indicates the presence of UNION or DISTINCT keywords. 具有属性3的行表示存在UNION或DISTINCT关键字。
The row with attribute 4 indicates if the query comes from an external database. 具有属性4的行指示查询是否来自外部数据库。 Name1 will contain the source if attribute 4 exists.
如果属性4存在,Name1将包含源。
The rows with attribute 5 (there could be multiple) indicate each table found in the query. 具有属性5的行(可能有多个)表示在查询中找到的每个表。 If the query is a UNION query, the Expression field has a split on the UNION keyword and the Name2 field has a system-generated table alias.
如果查询是UNION查询,则Expression字段对UNION关键字进行拆分,Name2字段具有系统生成的表别名。 For all other tables in a query, Name1 is the name of the table and Name2 is the alias, if there is one.
对于查询中的所有其他表,Name1是表的名称,Name2是别名(如果有)。
The rows with attribute 6 (there could be multiple) indicate each single field or expression in the query. 具有属性6的行(可能有多个)指示查询中的每个单个字段或表达式。 If there is no attribute 6 for the query, the behavior assumed is that all fields are included.
如果查询没有属性6,则假定的行为是包含所有字段。 The Expression field contains each field expression or name, and Name1 contains the field alias if there is one.
Expression字段包含每个字段表达式或名称,Name1包含字段别名(如果有)。
The rows with attribute 7 (there could be multiple) indicate each single join "ON" expression. 具有属性7的行(可能有多个)表示每个单独的连接“ON”表达式。 The Expression field contains the actual join expression.
Expression字段包含实际的连接表达式。 Name1 contains the first table in the join.
Name1包含连接中的第一个表。 Name2 contains the second table in the join.
Name2包含连接中的第二个表。
The row with attribute 8 contains the whole WHERE clause in the Expression field. 具有属性8的行包含Expression字段中的整个WHERE子句。 If there is no where clause, attribute 8 is omitted from the query.
如果没有where子句,则从查询中省略属性8。
The rows with attribute 9 (there could be multiple) indicate each single Group By expression in the GROUP BY clause of the query. 具有属性9的行(可能有多个)表示查询的GROUP BY子句中的每个Group By表达式。 The Expression field contains each group by expression.
表达式字段按表达式包含每个组。
The rows with attribute 11 (there could be multiple) indicate each single Order By expression in the ORDER BY clause of the query. 具有属性11的行(可能有多个)指示查询的ORDER BY子句中的每个单个Order By表达式。 The Expression field contains each order by expression.
表达式字段按表达式包含每个顺序。 Name1 has "D" or "d" to indicate that the sort is done in descending order.
Name1具有“D”或“d”以指示排序按降序完成。
The row with attribute 255 is the end of the query. 具有属性255的行是查询的结尾。
I'm not exactly sure what the Order field does, but I did find that it is not Null, and though it sometimes has a value of an empty string, it doesn't always have that value. 我不确定Order字段的作用,但我确实发现它不是Null,虽然它有时会有一个空字符串的值,但它并不总是具有该值。 Empty strings occur on attributes 5, 6, 7, and 9, but it is not always an empty string for those attributes.
属性5,6,7和9上出现空字符串,但对于这些属性,它并不总是空字符串。
Thanks to @Bobort great explanations, I was able to create a query that lists all queries in current database, with their input tables/queries, query type, and target table (for action queries). 感谢@Bobort很好的解释,我能够创建一个查询,列出当前数据库中的所有查询,包括它们的输入表/查询,查询类型和目标表(用于操作查询)。
I thought I could share that here. 我想我可以在这里分享一下。
SELECT MSysObjects.Name AS queryName,
Mid("SelectMakTblAppendUpdateDeleteXtab 777777PassThUnion ",([msysqueries]![Flag]-1)*6+1,6) AS queryType,
src.Name1 AS [Input],
MSysQueries.Name1 AS Target
FROM (MSysQueries INNER JOIN MSysObjects ON MSysQueries.ObjectId = MSysObjects.Id)
LEFT JOIN (select * from MSysQueries WHERE Attribute = 5 ) AS src
ON MSysQueries.ObjectId = src.ObjectId
WHERE (((MSysObjects.Name)>"~z") AND ((MSysQueries.Attribute) =1))
ORDER BY MSysObjects.Name, src.Name1;
To use, just create a query in SQL view and paste the above code. 要使用,只需在SQL视图中创建一个查询并粘贴上面的代码。
Further to Bobort and iDevlop's answers: 继Bobort和iDevlop的答案:
The row with attribute 1 indicates the type of the query. 具有属性1的行指示查询的类型。
CREATE TABLE...
) CREATE TABLE...
) The row with attribute 3 indicates the predicate. 具有属性3的行表示谓词。
The rows with attribute 5 (there could be multiple) indicate each FROM table/query found in the query 具有属性5的行(可能有多个)指示在查询中找到的每个FROM表/查询
The row with attribute 10 contains the whole HAVING clause in the Expression field. 具有属性10的行包含Expression字段中的整个HAVING子句。 If there is no HAVING clause, attribute 10 is omitted from the query.
如果没有HAVING子句,则从查询中省略属性10。
The Order
field is a BIG-ENDIAN binary value that contains an array of 4 bytes (binary fields can be added with VBA, but cannot be added using the UI, unless you copy and paste from a binary field in a system table.) However, in most databases, in the MSysQueries
table, you're unlikely to encounter binary values greater than 255, so you can shortcut the conversion to a byte by inspecting the byte at index 3. For example: Order
字段是一个BIG-ENDIAN二进制值,包含一个4字节的数组(二进制字段可以添加VBA,但无法使用UI添加,除非您从系统表中的二进制字段进行复制和粘贴。)但是在大多数数据库中,在MSysQueries
表中,您不太可能遇到大于255的二进制值,因此您可以通过检查索引3处的字节来快速转换为字节。例如:
Sub EnumOrder()
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset( _
" SELECT * FROM MSysQueries " & _
" WHERE Attribute = 6 " & _
"ORDER BY ObjectId Asc, [Order] Asc")
With rst
Do While Not .EOF
Debug.Print .Fields("ObjectId"), .Fields("Order")(3)
.MoveNext
Loop
.Close
End With
End Sub
Cumulative values occur for Attribute 3. So additional items include: 属性3会出现累积值。因此,其他项目包括:
I have written an extended article about the workings of the MSysQueries table. 我写了一篇关于MSysQueries表工作的扩展文章。 See How Access stores queries .
请参阅Access如何存储查询 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.