Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query to get the names of all tables in SQL Server 2008 Database

Is it possible to write a query that will give me the names of all the tables in an SQL Server database? I'm working on some 'after the fact' documentation on a system I didn't create and am looking for a shortcut to get a listing of the tables in a database.

like image 471
John H. Avatar asked May 21 '10 13:05

John H.


People also ask

What is the query to list all tables in database?

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.

How do I SELECT all table names?

The syntax to get all table names with the help of SELECT statement. mysql> use test; Database changed mysql> SELECT Table_name as TablesName from information_schema. tables where table_schema = 'test'; Output with the name of the three tables.


1 Answers

In a single database - yes:

USE your_database SELECT name FROM sys.tables 

Getting all tables across all databases - only with a hack.... see this SO question for several approaches how to do that: How do I list all tables in all databases in SQL Server in a single result set?

like image 132
marc_s Avatar answered Oct 06 '22 18:10

marc_s