Code Scraps: Retrieve all tables in a SQL Server database

MySQL has a really useful command called SHOW TABLES. It lists you all the tables available in the connected database.

Unfortunately Microsoft SQL Server doesn’t have such a useful shorthand command. The only way to get the list is to query the information schema (you can do something similar in MySQL too if you had to).

SELECT TABLE_NAME FROM MyDatabase.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = ‘BASE TABLE’

Change¬†MyDatabase for the name of your database and run the query, and you’ll get a result set of table names within your database.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.