Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to get list of affected tables in an Query Expand / Collapse
Author
Message
Posted Wednesday, January 16, 2013 4:40 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 21, 2014 1:11 PM
Points: 5, Visits: 48
Hi Guys,
First post here. Have a problem trying to build a work around for SQL Azure not supporting SELECT INTO...
As part of my solution, I need to get a table result containing a list of affected tables in a query. eg:
@sqlcmd='SELECT 
c.CustomerID,
c.CustomerName,
o.OrderID,
o.OrderDate
FROm Customer c
JOIN Orders o ON o.CustomerID=c.CustomerID'

I'm looking for a way to get the following output
Customer
Order

Any ideas? I was hoping there might be a system proc that might help...
Post #1407744
Posted Wednesday, January 16, 2013 1:17 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 12,957, Visits: 32,491
is this a one time kind of thing?
you could create a VIEW that uses the query, then check sys.sql_expression_dependencies for the objects, and then drop the view again:

select 
OBJECT_NAME(referencing_id) As ViewName,
OBJECT_NAME(referenced_id) As ReferencedObject
from sys.sql_expression_dependencies
WHERE OBJECT_NAME(referencing_id) = 'VW_MyTempVIEW'



Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1408061
Posted Wednesday, January 16, 2013 1:26 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:42 AM
Points: 12,957, Visits: 32,491
also, look at this rather long thread:
Select table names from queries

in that thread you'll find a lot of ideas, but the one i'm referring to is Eugene Elutin's posts on page 4 of the thread, where he is reading the execution plan cache and parsing the xml for the table values:


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1408066
Posted Thursday, January 17, 2013 12:31 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 21, 2014 1:11 PM
Points: 5, Visits: 48
Hi Lowell,

Thanks for taking the time to have a look. I will run some tests for both of these. I prefer creating a temp View and checking the dependancies and then dropping as I suspect that some of the system procs for obtaining execution paths are probably not available in Azure. I will update this thread with my test results and then eventually my work.
So far I have a script to create a temp table for a INSERT INTO SELECT... to replace the SELECT * INTO FROM (unsupported in Azure) which will allow any number of fields to be used without defining the destination temp table up front (which is my issue). This currently works on the results of one table (no joins) - your proposed solution may help me get to a temp table query with joins... I will post results.
Post #1408185
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse