scriptdom

How to extract cross databases references using scriptdom API

情到浓时终转凉″ 提交于 2020-05-23 09:50:29
问题 Microsoft has exposed the scriptdom API to parse and generate TSQL. I'm new to it and still playing with it. I want to know how to get the cross databases references from queries like this one. UPDATE t3 SET description = 'abc' FROM database1.dbo.table1 t1 INNER JOIN database2.dbo.table2 t2 ON (t1.id = t2.t1_id) LEFT OUTER JOIN database3.dbo.table3 t3 ON (t3.id = t2.t3_id) INNER JOIN database2.dbo.table4 t4 ON (t4.id = t2.t4_id) What I want is a list of the references: database1.dbo.table1.id

Parsing out complete dynamic SQL expressions from hundreds of stored procedures

99封情书 提交于 2019-12-24 01:06:34
问题 I've inherited a large application that has many hundreds of stored procedures, many of which use dynamic SQL. In order to get a better handle of the types of SQL I am dealing with, it would be extremely useful if I had a way to parse the query text of all these stored procedures and extract the complete expression for any dynamic SQL contained within. A simplified expression might be: declare @query nvarchar(max) set @query = 'SELECT col1,col2,col3 from ' + @DatabaseName + '.dbo.' +

How to get SelectStatement from Procedure?

眉间皱痕 提交于 2019-12-12 01:25:12
问题 This is a follow up question from here. I'm trying to use DACExtensions to retrieve the SelectStatement objects from a Procedure so that I can generate wrapper functions from my SSDT project using a T4 template. The problem is that the Nodes property of my Visitor object doesn't have any nodes in it. What am I missing? Here's my Visitor: public class SelectVisitor : TSqlFragmentVisitor { public SelectVisitor() { this.Nodes = new List<SelectStatement>(); } public List<SelectStatement> Nodes {