Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List names of all tables in a SQL Server 2012 schema

Tags:

sql

sql-server

I have a schema in SQL Server 2012.

Is there a command that I can run in SQL to get the names of all the tables in that schema that were populated by user?

I know a similar query for MySQL SHOW TABLES; but this does not work with SQL Server.

like image 233
AnkitGarg43 Avatar asked Jan 23 '14 15:01

AnkitGarg43


People also ask

How do I list all table names in a schema?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.


1 Answers

Your should really use the INFORMATION_SCHEMA views in your database:

USE <your_database_name> GO SELECT * FROM INFORMATION_SCHEMA.TABLES 

You can then filter that by table schema and/or table type, e.g.

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' 
like image 198
Kev Avatar answered Oct 12 '22 14:10

Kev