I am trying to see if there is a way to get the sql behind the data sources via a query on the Tableau "workgroup" database. We are trying to document our data sources and what tables they use and it is very tedious to have to go into each data source and get the SQL. We have over 230 data sources in the production environment.
The SQL for connections is stored in the xml files (either twb, twbx, or tds files). You'd need to access the xml files to pull the queries out, either manually or using the Document API:
I also found a thread with some replies that might be helpful: How to view underlying SQL query?