在存储过程中,寻找 table 名称(可能使用正则表达式?)排除两个模式

In a Stored Proc, looking for table names (maybe with regex?) excluding two schemas

我的公司正在将所有报告生成 table 移动到另一台服务器,为此我们需要找到存储过程访问实时 table 的所有实例并删除这些访问并替换它们可以访问快照。有很多存储过程我必须浏览,我的眼睛开始流血试图滚动浏览每个文件。我认为也许最好在每个存储过程中查看正则表达式。有没有更好的方法?

我正在查找所有情况,其中 FROM 或 JOIN 后跟不以 "Snapshot" 或 "EDI" 开头的 table(与报告关联的两个模式).另外,我确定有人不小心输入了 "FROm",因此不区分大小写会有所帮助。我也在尝试做 \s+ 因为有人可能在不小心之间输入了多个 space。

例如,要排除:

和不区分大小写的变体

我已经完成了教程 here,但仍有不足。到目前为止我有:

[fFjJ][RroO][oOiI][mMnN]\s+^(!snap|Snap|SNAP|EDI|edi|Edi)$

有什么想法吗?

编辑:我在 SSMS 2016 中使用查找和替换功能使用正则表达式。

虽然我面前没有 SSMS 2016,但 docs 似乎表明这会起作用。

(FROM|JOIN)\s+~((Snapshot|Edi)\.):a*>

细分

(FROM|JOIN)          --Match the word from or join
\s+                  --match at least one bit of whitespace
~(                   --don't call it a match if this comes next
   (Snapshot|Edi)\.  --the word Snapshot or Edi followed by a period
)                    --end of the don't match prefix
:a*                  --match any number of alphanumeric characters (this is your table name, so you may need a different character class depending on what characters you use in your tables)
>                    --match the end of a word

“查找和替换”对话框中还应该有一个选项来进行不区分大小写的匹配。

事实证明 Here on MSDN 使用 T-SQL 找到了更好的方法。我仍然必须逐个 SP,但它比使用正则表达式并忘记一些边界更快且更不容易出错。

SELECT OBJECT_NAME(referencing_id) AS referencing_entity_name, 
  o.type_desc AS referencing_desciption, 
  COALESCE(COL_NAME(referencing_id, referencing_minor_id), '(n/a)') AS referencing_minor_id, 
  referencing_class_desc,
  referenced_server_name, referenced_database_name, referenced_schema_name,
  referenced_entity_name, 
  COALESCE(COL_NAME(referenced_id, referenced_minor_id), '(n/a)') AS referenced_column_name,
  is_caller_dependent, is_ambiguous
FROM sys.sql_expression_dependencies AS sed
INNER JOIN sys.objects AS o ON sed.referencing_id = o.object_id
WHERE referencing_id = OBJECT_ID(N'EDI.Populate_IHP_OHN_Eligibility_Report')
  AND referenced_schema_name NOT IN ('EDI', 'Snapshot');