Skip to content
Advertisement

Find the names of last queried tables

I have a query inside my PHP program like

I want to know the names of the tables called in this query, including joined tables. The aim is to find the schema of the affected tables which is required for further operations.

Is there a direct query to do this or will I have to use some Regex?

Advertisement

Answer

You can retrieve the execution plan of a query, that includes all the tables involved in a query.

For example:

Result:

Here you can see that the third column includes the names of the tables involved in the query. The execution plan comes in tabular format (default) or in JSON format. The latter has more information than this one.

You can see running example at DB Fiddle.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement