SQL服务器:如何从数据库中的所有存储过程中找到特定值?

SQL Server : how can I find the specific value from all stored procedures in my database?

如何从我的 SQL 服务器数据库中的所有存储过程中找到特定值?

更具体地说,我想知道在指定的 table.

上的指定列中插入的值

例如:

dbo.sp_1

INSERT INTO [dbo].[Log] ([number]) 
VALUES (1);

dbo.sp_2

INSERT INTO [dbo].[Log] ([number]) 
VALUES (2);

dbo.sp_3

INSERT INTO [dbo].[Log] ([number]) 
VALUES (4);

所以,我期望的查询结果如下:

我找到了用于 somewhat-similar 任务的片段,但是,我不必解析值。如果您真的必须解析 sql,这可能会让您接近。抱歉,剩下的解析就交给你了

DECLARE @NonEscapeTextToFindLike NVARCHAR(MAX) = 'INSERTINTO\[dbo\].\[LOG\](\[number\])VALUES('
DECLARE @NonEscapeTextToFind NVARCHAR(MAX) = 'INSERTINTO[dbo].[LOG]([number])VALUES('

;WITH Procs AS
(
    SELECT 
        StoredProcedure = name,
        StoredProcedureText = OBJECT_DEFINITION(object_id),
        NoBlankText = REPLACE(REPLACE(REPLACE(REPLACE(OBJECT_DEFINITION(object_id),' ',''),CHAR(9),''),CHAR(10),''),CHAR(13),'')
    FROM   
        sys.procedures
)

SELECT
    *,
    StartOfPossibleInt = CHARINDEX(@NonEscapeTextToFind, Procs.NoBlankText) + LEN(@NonEscapeTextToFind)
FROM
    Procs
WHERE
    Procs.NoBlankText LIKE '%'+@NonEscapeTextToFindLike+'%' ESCAPE '\'