Obtain dependencies of a view

1

I need to get the dependencies seen, that is, which objects of the database need to be created before the view in question.

Example:

  • Tables
  • Functions
  • Views (if it depends on another view)

I tried to consult the table information_schema.views but it does not give me the information I need since it shows me only the following fields:

In the field VIEW_DEFINITION you will find the creation code of the view, which you could use to analyze it and extract the objects involved in some way, but I really do not know how to do it.

Is there any way to find the dependencies of the views in MySQL?

    
asked by Blasito 23.05.2018 в 20:53
source

1 answer

1

This query provides you with the necessary information to make decisions in this case. Includes outline, view, table and type of table (table or view):

SELECT
  tab.TABLE_SCHEMA AS 'esquema',
  views.TABLE_NAME AS 'vista',
  tab.TABLE_NAME AS 'tabla',
  tab.TABLE_TYPE AS 'tipo'
FROM
    information_schema.'TABLES' AS tab
    INNER JOIN information_schema.VIEWS AS views 
       ON views.VIEW_DEFINITION LIKE CONCAT('%'', tab.TABLE_NAME, ''%');
    
answered by 26.05.2018 / 18:34
source