Finding Tables from Procedures has Insert Script

Ram Kumar 1 Reputation point
2022-01-19T14:16:36.377+00:00

I've Stored Procedures list that has Insert statements. I need to find the tables that has Insert Statements in a SP and put the result in a temp table . Can anyone tell the ways to find it. Appreciate your assistance.

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,559 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 102.2K Reputation points
    2022-01-19T22:46:26.063+00:00

    To start with: this is not a trivial problem.

    You can have a look at my article Where Is that Table Used? where I discuss some options. But you will find that no option answers your question in full. But you could start with building a fulltext-indexed database from the source code and search for INSERT and then see if you can work from that result.

    If you are well acquainted with Python and regular expressions, and you are on SQL 2017 or later, you could search the code with regular expression. Or apply regexps to the result from the full-text index. But this can be difficult if you have table names like [My Funky Table].

    0 comments No comments

  2. LiHong-MSFT 10,046 Reputation points
    2022-01-20T01:43:11.263+00:00

    Hi,@Ram Kumar
    Please refer to the answers in this link:How can I get the list of tables in the stored procedure?

    Best regards,
    LiHong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.