SQL Server Tutorialprovides basic and advanced concepts of C# for beginners and professionals.

SQL Show Tables (Listing Tables)

Back to: SQL Server Tutorial

In Microsoft SQL Server, you can list tables in a few different ways depending on your environment (SQL Server Management Studio, command line, etc.). Here’s how you can do it:

Using SQL Server Management Studio (SSMS)

  1. Connect to your SQL Server instance in SSMS.
  2. Expand the database where you want to view the tables.
  3. Expand the "Tables" folder under the database. This will show you a list of all tables in that database.

Using T-SQL Query

You can use T-SQL queries to list tables in a database. Here are a few methods:

  1. List Tables in the Current Database

    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'prefix%';

    This query selects all rows from the INFORMATION_SCHEMA.TABLES view where TABLE_TYPE is 'BASE TABLE'. This will show you all the tables in the current database.

  2. List Tables with Schema Information

    SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';

    This query also includes the schema of each table, which can be useful if you have multiple schemas.

  3. Using sys.tables

    SELECT name FROM sys.tables;

    The sys.tables system catalog view returns one row for each table object in the database.

  4. Using sysobjects (Legacy)

    SELECT name FROM sysobjects WHERE type = 'U'; -- 'U' stands for user tables

    Note that sysobjects is a legacy system table; it’s generally recommended to use sys.tables for newer code.

Filtering Tables

You can also filter the tables based on names or other criteria:

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'prefix%';

Replace 'prefix%' with the specific table name or pattern you are interested in.

Scroll to Top