简体   繁体   English

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

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

How can I find the specific value from all stored procedures in my SQL Server database?如何从我的 SQL Server 数据库中的所有存储过程中找到特定值?

To be more specific, I want to know the value that is inserted into the specified column on the specified table.更具体地说,我想知道插入到指定表的指定列中的值。

For example:例如:

  • A database has 3 stored procedures;一个数据库有3个存储过程; dbo.sp_1 , dbo.sp_2 , dbo.sp_3 dbo.sp_1dbo.sp_2dbo.sp_3
  • And that database also has a [Log] table which has a [number] column并且该数据库还有一个[Log]表,其中有一个[number]

dbo.sp_1 dbo.sp_1

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

dbo.sp_2 dbo.sp_2

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

dbo.sp_3 dbo.sp_3

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

So, the query results I expect are as follows:所以,我期望的查询结果如下:

在此处输入图像描述

I found a snippet that was used for a somewhat-similar task, however, I did not have to parse values.我找到了一个用于类似任务的片段,但是,我不必解析值。 This may get you close if you really have to parse the sql.如果您真的必须解析 sql,这可能会让您接近。 Sorry, the rest of the parsing will be left up to you抱歉,剩下的解析交给你

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 '\'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从特定数据库下载所有存储过程 - How can I download all stored procedures from a specific database 如何在SQL Server中查找使用“我的数据库”的存储过程 - How to find stored procedures which are using 'My Database' in SQL Server 如果我的所有sql server数据库访问都是通过存储过程完成的 - If all my sql server database access is done thru stored procedures 如何拒绝 SQL 服务器中特定用户的所有存储过程? - How to deny all stored procedures to specific user in SQL Server? 如何在SQL Server数据库中一次删除所有存储过程? - How to drop all stored procedures at once in SQL Server database? 如何统计SQL服务器中一个数据库的所有存储过程? - How to count all stored procedures in the SQL Server for a database? 我可以在数据库的不同存储过程中引用SQL Server中的CONSTANT这样的东西吗? - Is there such a thing as a CONSTANT in SQL Server that I can refer to in different stored procedures in my database? MS SQL Server-如何将所有存储过程从我的机器导出到我的朋友机器? - MS SQL Server - How to export all Stored procedures from my machine to my friends machine? 如何使用SQL Server Management Studio将所有存储过程从一个数据库传输到另一个数据库 - How to transfer all stored procedures from one database to another with SQL Server Management Studio Sql Server 2000 - 如何找出当前正在运行的存储过程? - Sql Server 2000 - How can I find out what stored procedures are running currently?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM