问题描述
我使用带有Where子句的脚本创建了一个扩展事件会话,以过滤引用名称为MySchema.MyTable的表的命令:
I created an Extended Event Session using a script with a Where clause in order to filter commands which refers to a table whose name is MySchema.MyTable:
WHERE ([sqlserver].[like_i_sql_unicode_string]([sqlserver].[sql_text],N'%MySchema.MyTbl%'))
问题在于表格可以通过以下四种方式之一出现:
The problem is that the table can appear in one of the 4 following ways:
MySchema.MyTable
[MySchema].MyTable
MySchema.[MyTable]
[MySchema].[MyTable]
我可以创建一个长的Where子句,其中包含所有这些选项以及它们之间的或"运算符(以找到一种很好的解决方案,解决字符的歧义],[],但这不是很优雅.我希望我可以使用Replace运算符来删除那些字符(],[),但我不知道如何.有什么建议吗?
I can create a long Where clause with al those options and the "Or" operator between them (a to find a good solution to the ambiguity of the characters ],[), but it is not very elegant.I wish I could use Replace operator in order to remove those characters (],[) but I don't know how..Any suggestions?
推荐答案
经过一番调查,我认为一个好的解决方案是使用object_id进行过滤,而不是通过操纵SQL字符串来查找对象名称
After some investigation I think a good solution would be to filter by the object_id instead of by manipulating the SQL string in order to find the object name
这篇关于如何在扩展事件中过滤表名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!