SQL Script parsing to retrieve table and column names

If I have a SQL script, there is a way to go through and extract the used columns and tables referenced in the table:

Script:

Select t1.first, t1.last, t2.car, t2.make, t2.year from owners t1 left join cars t2 on t1.owner_id = t2.owner_id 

Conclusion:

 Table Column owners first owners last owners owner_id cars car cars make cars year cars owner_id 
+5
source share
1 answer

This is what you want in SQL Server:

 select t.name as [Table], c.name as [Column] from sys.columns c inner join sys.tables t on c.object_id = t.object_id 
0
source

All Articles