Never heard of ScriptDOM? Neither had we…okay, except Kevin, who obviously knows all. Apparently, the documentation is scarce. Mala Mahadevan uses it, loves it, and graciously offered to come back to the podcast to educate us and our listeners on a product that can help us parse, process and format our SQL queries.
Microsoft.SQLServer.TransactSQL.ScriptDOM
ScriptDOM Classes
Download and install sqlpackage
Articles on ScriptDOM
Mala’s blog post: Formatting T-SQL Scripts using ScriptDOM and PowerShell
Microsoft PM Arvind Shyamsunder’s video: T-SQL Swiss Knife: Using the ScriptDom T-SQL Parser
Microsoft PM Arvind Shyamsunder’s blog post: Programmatically parsing Transact SQL (T-SQL) with the ScriptDom parser
Dan Guzman’s blog post: Microsoft SQL Server Script DOM
Aaron Bertrand’s blog post: Parse parameter default values using PowerShell
Get your SQL Data Partners Podcast and SQL Trail T-shirt!
Support the livestream here

Our Guest
Mala Mahadevan
Mala Mahadevan is a senior database professional with over 20 years of experience working with data, primarily in SQL Server and related technologies. She has been volunteering with SQL Server community for the past 15 years and is also a recipient of the PASSion award for being an outstanding volunteer. She is a featured blogger on sqlservercentral.com and also blogs frequently at curiousaboutdata.com. She is active on Twitter as @sqlmal.
Never Miss An Episode
Subscribe to get podcast notifications by email.
It’s a beautifully engineered [product], but because it’s not documented, it’s not easy for someone to just go in there and use it.
Mala Mahadevan
3 Takeaways
- ScriptDOM allows you to create a document object model of a T-SQL query. You can then parse elements of the query just like SQL Server Management Studio does. It creates an abstract syntax tree (AST) representing the query.
- ScriptDOM provides two ways to parse the resulting tree: walk through the elements directly or use the Visitor pattern to find just the elements you want.
- ScriptDOM allows you to parse an existing query, check for syntax errors, and perform static code analysis. It will not generate a new T-SQL query from a syntax tree, so it is not an object-relational mapper (ORM).
Leave a Reply
You must belogged in to post a comment.