How practise you lot respect names of all tables inwards a database is a recent SQL interview questions asked to ane of my friend. There are many ways to respect all tabular array names shape whatever database similar MySQL as well as SQL Server. You tin larn tabular array names either from INFORMATION_SCHEMA or sys.tables based upon whether you lot are using MySQL or Sql Server database. This is non a pop inquiry similar when to utilization truncate as well as delete or correlated vs noncorrelated subquery which you lot tin await close all candidate gear upwardly good but this is quite mutual if you lot are working on whatever database e.g. MySQL. In this SQL tutorial nosotros volition meet examples of getting names of all tables from MySQL as well as SQL Server database. In MySQL in that place are ii ways to respect names of all tables, either yesteryear using "show" keyword or by query INFORMATION_SCHEMA. In case of SQL Server or MSSQL, You tin either utilization sys.tables or INFORMATION_SCHEMA to larn all tabular array names for a database. By the agency if you lot are novel inwards MySQL server as well as exploring it , you lot may respect this listing of frequently used MySQL server commands handy.
How to respect advert of all tables inwards MySQL database
Let's meet instance of using INFORMATION_SCHEMA and demo keyword to find all tabular array names from MySQL database:
mysql> SELECT table_name FROM information_schema.tables WHERE table_type = 'base table' AND table_schema='test';
+------------+
| TABLE_NAME |
+------------+
| subdivision |
| employee |
| role |
| user |
+------------+
4 rows inwards laid (0.00 sec)
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| department |
| employee |
| role |
| user |
+----------------+
4 rows inwards laid (0.00 sec)
While working inwards MySQL database I prefer to utilization show tables later on selecting database e.g use database_name. Compact as well as intuitive syntax of show keyword makes it slowly to show all tabular array names of selected database from merely unproblematic query. On the other manus using INFORMATION_SCHEMA is to a greater extent than full general agency as well as you lot tin fifty-fifty transcend advert of database to SELECT query.
How to respect advert of all tables inwards SQL Server database
In final subdivision nosotros accept seen SQL query to demo names of all tables inwards MySQL database as well as directly nosotros volition meet SQL query instance for SQL Server database. Here is instance of getting all tabular array names inwards MSSQL or SQL Server database:
USE test; //SELECT DATABASE
SELECT table_name FROM information_schema.tables WHERE table_type = 'base table'
SELECT table_name FROM information_schema.tables WHERE table_type = 'base table'
or you lot tin utilization sys.tables to larn all tabular array names from selected database equally shown inwards next SQL query
USE test; //SELECT DATABASE
SELECT * FROM sys.tables
SELECT * FROM sys.tables
That's all on how to respect all tabular array names from database inwards MySQL as well as SQL Server. I volition update this article if I constitute similar SQL query for other database similar Oracle, Sybase or PostgreSQL etc. Though I haven't tried PostgreSQL but I am expecting show tables to operate there. allow me know if whatever of you lot guys tried to respect names of all tables from electrical flow database inwards PostgreSQL.
Further Learning
Introduction to SQL
The Complete SQL Bootcamp
SQL for Newbs: Data Analysis for Beginners