How do I get list of all tables in a database usin

2018-12-31 17:59发布

What is the best way to get the names of all of the tables in a specific database on SQL Server?

17条回答
看淡一切
2楼-- · 2018-12-31 19:02

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
查看更多
倾城一夜雪
3楼-- · 2018-12-31 19:04
SELECT * FROM information_schema.tables
where TABLE_TYPE = 'BASE TABLE'

SQL Server 2012

查看更多
牵手、夕阳
4楼-- · 2018-12-31 19:04

select * from sysobjects where xtype='U'

查看更多
何处买醉
5楼-- · 2018-12-31 19:04

Please use this. You will get table names along with schema names:

SELECT SYSSCHEMA.NAME, SYSTABLE.NAME
FROM SYS.tables SYSTABLE
INNER JOIN SYS.SCHEMAS SYSSCHEMA
ON SYSTABLE.SCHEMA_ID = SYSSCHEMA.SCHEMA_ID
查看更多
后来的你喜欢了谁
6楼-- · 2018-12-31 19:05
SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE='BASE TABLE' 
ORDER BY TABLE_NAME
查看更多
登录 后发表回答