I have a string representing a SQL query, and I need to extract the names of the tables from that string. For example:
SELECT * FROM Customers
Would return "Customers". Or
SELECT * FROM Customers c, Addresses a WHERE c.CustomerName='foo'
SELECT a.AddressZip FROM Customers c
INNER JOIN Addresses a ON c.AddressId=a.AddressId
Would return "Customers, Addresses". Getting more advanced:
(SELECT B FROM (SELECT C FROM (SELECT Element AS C FROM MyTable)))
Would simply return "MyTable"
(Note, I may have typo'd the queries but you get the idea).
What would be the best/most accurate way of accomplishing this?