How to get a list of MySQL views?
You can use different MySQL commands to get a list of MySQL views. You can retrieve views from a specific database, or even include system (sys) views along with database views. Each command provides a distinct way to gather information about views in MySQL databases.
-
Get a list of MySQL views from a specific database
Get views from specific database using information_schema virtual database
select table_name as view_name from information_schema.views where table_schema = "learn_sql";
Output
+-------------+ | view_name | +-------------+ | user_orders | +-------------+ 1 row in set (0.00 sec)
Get the views from learn_sql database using filter
show full tables in learn_sql where table_type='VIEW';
Output
+---------------------+------------+ | Tables_in_learn_sql | Table_type | +---------------------+------------+ | user_orders | VIEW | +---------------------+------------+ 1 row in set (0.00 sec)
The above SQL query retrieves a list of all views in the database "learn_sql" by filtering results where the table_type column is equal to 'VIEW'.
-
Get all views from database without specifying database name
show full tables where table_type = 'VIEW';
Output
+---------------------+------------+ | Tables_in_learn_sql | Table_type | +---------------------+------------+ | user_orders | VIEW | +---------------------+------------+ 1 row in set (0.00 sec)
-
Get all views along with sys database views
select table_schema, table_name from information_schema.tables where table_type like 'VIEW';
Output
+--------------+-----------------------------------------------+ | TABLE_SCHEMA | TABLE_NAME | +--------------+-----------------------------------------------+ | learn_sql | user_orders | | my_form | employeenames | | sys | host_summary | | sys | host_summary_by_file_io | | sys | host_summary_by_file_io_type | | sys | host_summary_by_stages | | sys | host_summary_by_statement_latency | | sys | host_summary_by_statement_type | | sys | innodb_buffer_stats_by_schema | | sys | innodb_buffer_stats_by_table | | sys | innodb_lock_waits | | sys | io_by_thread_by_latency | | sys | io_global_by_file_by_bytes | | sys | io_global_by_file_by_latency | | sys | io_global_by_wait_by_bytes | | sys | io_global_by_wait_by_latency | | sys | latest_file_io |
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Sql
- Check constraint in MySQL
- Drop foreign id column (user_id) in MySQL
- How to check the MySQL version
- Database connection using mySQLi with object-oriented
- MySQL create procedure example
- Get data in random order with limit from table using mysql
- How to create a new table from existing table in SQL
- How to show database tables in mysql using command line
- How to Rename column name in MySql ?
- How to retrieve data from two tables with one SQL statement
- Change existing MySQL table column id to autoincrement
- Self join in mysql employee manager example
- Create column after a column in existing table using query in MySQL
- How to get yesterday's date in MySQL ?
- How to check column exists or not in table using MySQL
- Clear the terminal screen in MySQL within the Windows powershell
- How to create function in MySQL ?
- Get full name of a person in SQL using function
- How to drop function in MySQL ?
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Get number of connections being used by a specific user in MySQL
- Get create table Query from existing table in phpMyAdmin
- SQL query to delete all rows older than 30 days
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- SQL query to delete records older than 6 months