Parse SQL statement

How can I parse a SQL statement (for SQL Server) to extract columns and parameters info (Name, DataType) without using ActiveQueryBuilder.


  • sql server select first row from a group
  • storing a Book using SQL Server
  • invalid object name 'tableName' error
  • How to find fifth highest salary in a single query in SQL Server
  • Can't connect to SQL 2008 database using .NET Core 2.0
  • Drop a temporary table if it exists
  • User permission error when accessing “user instance” database from ASP.NET
  • How to store an Image URL in database and use it in ASP.NET MVC?
  • GUID not being generated automatically when db.submitchanges()
  • Stored procedure error::Invalid object name..Need help
  • Database design for Magazine website with flexible horizontal menus
  • Needing to get a list of strings into a webservice
  • 2 Solutions collect form web for “Parse SQL statement”

    You can try with TSql100Parser class

    Link :

    Sample :

     bool fQuotedIdenfifiers = false;
     var _parser = new TSql100Parser(fQuotedIdenfifiers);
     SqlScriptGeneratorOptions options = new SqlScriptGeneratorOptions();
     options.SqlVersion = SqlVersion.Sql100;
     options.KeywordCasing = KeywordCasing.UpperCase;
     _scriptGen = new Sql100ScriptGenerator(options);
     IScriptFragment fragment;
     IList<ParseError> errors;
     using (StringReader sr = new StringReader(inputScript))
           fragment = _parser.Parse(sr, out errors);
     if (errors != null && errors.Count > 0)
           StringBuilder sb = new StringBuilder();
           foreach (var error in errors)
               sb.AppendLine("offset " + error.Offset.ToString());
           var errorsList = sb.ToString();
           String script;
           _scriptGen.GenerateScript(fragment, out script);
           var result = script;

    Well, parsing the statement is much different than getting back the schema of the resulting statement. Parsing would mean your just validating the syntax of the query. However, to get back the resulting schema involves parsing so how about you try this.

    DataTable table = new DataTable();
    SqlDataAdapter sda = new SqlDataAdapter("select * from yourtable", "your connection string");
    sda.FillSchema(table, SchemaType.Source);
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.