What is the best way to get the names of all of the tables in a specific database on SQL Server?
The downside of INFORMATION_SCHEMA.TABLES
is that it also includes system tables such as dtproperties
and the MSpeer_...
tables, with no way to tell them apart from your own tables.
I would recommend using sys.objects (the new version of the deprecated sysobjects view), which does support excluding the system tables:
select *
from sys.objects
where type = 'U' -- User tables
and is_ms_shipped = 0 -- Exclude system tables