
- SQL Tutorial
- SQL - Home
- SQL - Overview
- SQL - RDBMS Concepts
- SQL - Databases
- SQL - Syntax
- SQL - Data Types
- SQL - Operators
- SQL - Expressions
- SQL Database
- SQL - Create Database
- SQL - Drop Database
- SQL - Select Database
- SQL - Rename Database
- SQL - Show Databases
- SQL - Backup Database
- SQL Table
- SQL - Create Table
- SQL - Show Tables
- SQL - Rename Table
- SQL - Truncate Table
- SQL - Clone Tables
- SQL - Temporary Tables
- SQL - Alter Tables
- SQL - Drop Table
- SQL - Delete Table
- SQL - Constraints
- SQL Queries
- SQL - Insert Query
- SQL - Select Query
- SQL - Select Into
- SQL - Insert Into Select
- SQL - Update Query
- SQL - Delete Query
- SQL - Sorting Results
- SQL Views
- SQL - Create Views
- SQL - Update Views
- SQL - Drop Views
- SQL - Rename Views
- SQL Operators and Clauses
- SQL - Where Clause
- SQL - Top Clause
- SQL - Distinct Clause
- SQL - Order By Clause
- SQL - Group By Clause
- SQL - Having Clause
- SQL - AND & OR
- SQL - BOOLEAN (BIT) Operator
- SQL - LIKE Operator
- SQL - IN Operator
- SQL - ANY, ALL Operators
- SQL - EXISTS Operator
- SQL - CASE
- SQL - NOT Operator
- SQL - NOT EQUAL
- SQL - IS NULL
- SQL - IS NOT NULL
- SQL - NOT NULL
- SQL - BETWEEN Operator
- SQL - UNION Operator
- SQL - UNION vs UNION ALL
- SQL - INTERSECT Operator
- SQL - EXCEPT Operator
- SQL - Aliases
- SQL Joins
- SQL - Using Joins
- SQL - Inner Join
- SQL - Left Join
- SQL - Right Join
- SQL - Cross Join
- SQL - Full Join
- SQL - Self Join
- SQL - Delete Join
- SQL - Update Join
- SQL - Left Join vs Right Join
- SQL - Union vs Join
- SQL Keys
- SQL - Unique Key
- SQL - Primary Key
- SQL - Foreign Key
- SQL - Composite Key
- SQL - Alternate Key
- SQL Indexes
- SQL - Indexes
- SQL - Create Index
- SQL - Drop Index
- SQL - Show Indexes
- SQL - Unique Index
- SQL - Clustered Index
- SQL - Non-Clustered Index
- Advanced SQL
- SQL - Wildcards
- SQL - Comments
- SQL - Injection
- SQL - Hosting
- SQL - Min & Max
- SQL - Null Functions
- SQL - Check Constraint
- SQL - Default Constraint
- SQL - Stored Procedures
- SQL - NULL Values
- SQL - Transactions
- SQL - Sub Queries
- SQL - Handling Duplicates
- SQL - Using Sequences
- SQL - Auto Increment
- SQL - Date & Time
- SQL - Cursors
- SQL - Common Table Expression
- SQL - Group By vs Order By
- SQL - IN vs EXISTS
- SQL - Database Tuning
- SQL Function Reference
- SQL - Date Functions
- SQL - String Functions
- SQL - Aggregate Functions
- SQL - Numeric Functions
- SQL - Text & Image Functions
- SQL - Statistical Functions
- SQL - Logical Functions
- SQL - Cursor Functions
- SQL - JSON Functions
- SQL - Conversion Functions
- SQL - Datatype Functions
- SQL Useful Resources
- SQL - Questions and Answers
- SQL - Quick Guide
- SQL - Useful Functions
- SQL - Useful Resources
- SQL - Discussion
SQL - Show Tables (Listing Tables)
There are several instances when you need to retrieve a list of tables from your database. This could be done for testing purposes, to identify any existing tables before adding or removing any, or for any other reason. This tutorial will discuss how we can list down all the table in MySQL, SQL Server and Oracle using simple SQL commands.
MySQL - Listing Tables
You can use SQL SHOW TABLES statements in MySQL to list down all the tables available in a selected database.
Syntax
Following is the syntax to list all the tables in SQL in MySQL −
SHOW TABLES;
Example
Following is an example which will list down all the tables from a testDB database.
USE testDB; SHOW TABLES;
This will display the following output depending on the number of tables available in your database.
Tables_in_testDB |
---|
CALENDAR |
CUSTOMERS |
COMPANIES |
SALARY |
SQL Server - Listing Tables
SQL Server does not provide SHOW TABLE command in an SQL Server. Instead, we can use the "SELECT" statement to retrieve information about tables in a database. We have three different commands to use with the SELECT statement to list all the tables in a database −
sys.tables
information_schema.tables
sysobjects
The SYS.TABLES View
Following is the syntax to list down all the tables in SQL using the SYS.TABLES view −
SELECT * FROM SYS.TABLES;
Following is the output of the above query −
name | object_id | principal_id | schema_id |
---|---|---|---|
CUSTOMER | 4195065 | NULL | 1 |
ORDERS | 68195293 | NULL | 1 |
COMPANIES | 100195407 | NULL | 1 |
SALARY | 2107154552 | NULL | 1 |
The INFORMATION_SCHEMA.TABLES View
Following is the syntax to list down all the tables in SQL using the INFORMATION_SCHEMA.TABLES view −
SELECT table_name, table_type FROM INFORMATION_SCHEMA.TABLES;
Following is the output of the above query −
table_name | table_type |
---|---|
CUSTOMER | BASE TABLE |
ORDERS | BASE TABLE |
COMPANIES | BASE TABLE |
SALARY | BASE TABLE |
The SYSOBJECTS View
You can use SYSOBJECTS view to retrieve the information of all the objects created in SQL Server database, including stored procedures, views, system tables and user-defined tables. Following is the basic syntax of using sysobjects view −
SELECT name, id, xtype FROM sysobjects WHERE xtype = 'U';
Value | Meaning |
---|---|
AF | Aggregate function (CLR) |
C | CHECK constraint |
D | Default or DEFAULT constraint |
F | FOREIGN KEY constraint |
L | Log |
FN | Scalar function |
FS | Assembly (CLR) scalar-function |
FT | Assembly (CLR) table-valued function |
IF | In-lined table-function |
IT | Internal table |
P | Stored procedure |
PC | Assembly (CLR) stored-procedure |
PK | PRIMARY KEY constraint (type is K) |
RF | Replication filter stored procedure |
S | System table |
SN | Synonym |
SQ | Service queue |
TA | Assembly (CLR) DML trigger |
TF | Table function |
TR | SQL DML Trigger |
TT | Table type |
U | User table |
UQ | UNIQUE constraint (type is K) |
V | View |
X | Extended stored procedure |
This will produce following result −
name | id | xtype |
---|---|---|
CUSTOMER | 4195065 | U |
ORDERS | 68195293 | U |
COMPANIES | 100195407 | U |
SALARY | 2107154552 | U |
Oracle - Listing Tables
There are following three SQL SELECT statements which you can use to list down the tables available in Oracle.
Listing ALL Tables
Following is the SQL SELECT statement which will list down all the available tables in an Oracle Database.
SELECT owner, table_name FROM ALL_TABLES
Listing DBA Tables
Following is the SQL SELECT statement which will list down all the DBA related tables in an Oracle Database.
SELECT owner, table_name FROM DBA_TABLES
Listing USER Tables
Following is the SQL SELECT statement which will list down all the USER created tables in an Oracle Database.
SELECT owner, table_name FROM USER_TABLES
Listing ALL Views
Following is the SQL SELECT statement which will list down all the views available in an Oracle Database.
SELECT view_name FROM ALL_VIEWS;