TSqlParser 0.1.2
dotnet add package TSqlParser --version 0.1.2
NuGet\Install-Package TSqlParser -Version 0.1.2
<PackageReference Include="TSqlParser" Version="0.1.2" />
<PackageVersion Include="TSqlParser" Version="0.1.2" />
<PackageReference Include="TSqlParser" />
paket add TSqlParser --version 0.1.2
#r "nuget: TSqlParser, 0.1.2"
#:package TSqlParser@0.1.2
#addin nuget:?package=TSqlParser&version=0.1.2
#tool nuget:?package=TSqlParser&version=0.1.2
TSqlParser
Why another parser ?
The goal of this project is to be able analyze T-Sql statements (similar to sp_depends someprocedurename) to get a list of tables touched with the operation type (UPDATE, INSERT, SELECT or DELETE) without having a connection to the database. If you have connection to the database, then definitely first review if sp_depends satisfies your requirements.
How is this different ?
sp_depends does not distinguish between updates and inserts and does not report on data being deleted from tables. And obviously, sp_depends works only on database objects - ie sql stored procedures. If you are running EF framework, that logs SQL statements that you want to analyze, sp_depends will not help. This TSqlParser is also able to find temp tables and table variables used within the SQL text that needs to be analyzed.
Cool, how can I use it ?
Reference TSqlParser.Core.dll and init SqlScriptAnalyzer. The ParserResults object has the collection of tables and stored procedures invoked.
string _sqlText = "INSERT INTO table1
SELECT a, b, c
FROM table2
EXEC pr_some_inner_procedure ";
SqlScriptAnalyzer _analyzer = new SqlScriptAnalyzer();
ParserResults actual = await _analyzer.AnalyzeSqlTextAsync(_sqlText);
Console.WriteLine(actual.ToString());
Parsing Result
- Tables touched
- table1 - INSERT
- table2 - SELECT
- Procedures Invoked
- pr_some_inner_procedure
code on github @ https://github.com/console-writeline/t-sql-parser nuget package @ https://www.nuget.org/packages/TSqlParser
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net47 is compatible. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.7
- Microsoft.SqlServer.TransactSql.ScriptDom (>= 14.0.3811.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.