Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do the equivalent of "SHOW TABLES" in T-SQL?

I would like to do a lookup of tables in my SQL Server 2005 Express database based on table name. In MySQL I would use SHOW TABLES LIKE "Datasheet%", but in T-SQL this throws an error (it tries to look for a SHOW stored procedure and fails).

Is this possible, and if so, how?

like image 898
Andrew Crowe Avatar asked Sep 23 '08 22:09

Andrew Crowe


People also ask

How can I see tables in SQL Server?

Using SQL Server Management Studio In Object Explorer, select the table for which you want to show properties. Right-click the table and choose Properties from the shortcut menu. For more information, see Table Properties - SSMS.

How do I get a list of table names in SQL?

In MySQL, there are two ways to find the names of all tables, either by using the "show" keyword or by query INFORMATION_SCHEMA. In the case of SQL Server or MSSQL, You can either use sys. tables or INFORMATION_SCHEMA to get all table names for a database.


2 Answers

I know you've already accepted an answer, but why not just use the much simpler sp_tables?

sp_tables 'Database_Name' 
like image 97
JustinD Avatar answered Sep 22 '22 23:09

JustinD


This will give you a list of the tables in the current database:

Select Table_name as "Table name" From Information_schema.Tables Where Table_type = 'BASE TABLE' and Objectproperty  (Object_id(Table_name), 'IsMsShipped') = 0 

Some other useful T-SQL bits can be found here: http://www.devx.com/tips/Tip/28529

like image 25
Hector Sosa Jr Avatar answered Sep 20 '22 23:09

Hector Sosa Jr