Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:18:36+00:00 2026-06-13T05:18:36+00:00

I have a random .sql file with long sql query. I need to runtime

  • 0

I have a random .sql file with long sql query. I need to runtime get all table names from the insert sql statement to put into an array. I am able to get the table names (Inventory.tableA) out if the insert statement is in (one line) like the format below:

...
Insert into Inventory.tableA;
...

However, if the Insert statement is in multiple lines like below e.g.

Insert into 
Inventory.tableA;

OR

Insert into 
(blank line)
(blank line)
Inventory.tableA;

Then my query to retrieve the table name will fail. Can you advise how i can get the table name out from the long sql query which the insert statement can be in either one line or multiple lines? What is the best approach here?

Below is the c# query i tried which can handle for 1 line.

public List<string> GetAllTablesNames(string sp)
        {
            List<string> output = new List<string>();

            string[] contentSplit = sp.Split(new string[] { "INSERT INTO " }, StringSplitOptions.None);
            for (int a = 1; a < contentSplit.Length; a++)
            {
                string[] sa_tableName = contentSplit[a].Substring(0, contentSplit[a].IndexOf("\r")).Trim().Split('.');

                    output.Add(sa_tableName[0] + "." + sa_tableName[1]);
            }

            return output.Distinct().ToList();
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:18:37+00:00Added an answer on June 13, 2026 at 5:18 am

    Use singleline mode

    List<string> tables= Regex.Matches("yourInput",@"Insert into\s+(.*?)[\s\(]+"
    ,RegexOptions.Singleline|RegexOptions.IgnoreCase)
    .Cast<Match>().Select(x=>x.Groups[1].Value)
    .ToList<string>();
    
    //tables contains all the table names
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Select n random rows from SQL Server table I have database and
I have a SQL database that contains a field. I can get all of
I am using SQL Server 2008. I have a query that pulls two random
If I have a table of random values in a sql table, how can
I got requirements- 1. Have random values in a List/Array and I need to
I have a problem with random number generating in C# I have tried all
I have the following code: from random import randint,choice add=lambda x:lambda y:x+y sub=lambda x:lambda
I have file of some random text size = 27 gb and after compression
I have a SQL Server table full of orders that my program needs to
In SQL Server, I have a table where a column A stores some data.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.