在SQL Server上获得特定数据库中所有表的名称的最佳方法是什么?


当前回答

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE='BASE TABLE' 
ORDER BY TABLE_NAME

其他回答

exec sp_msforeachtable 'print ''?'''
--for oracle
select tablespace_name, table_name from all_tables;

这个链接可以提供更多的信息 主题

SELECT * FROM information_schema.tables
where TABLE_TYPE = 'BASE TABLE'

SQL Server 2012

SQL Server 2000, 2005, 2008, 2012, 2014, 2016, 2017或2019:

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'

仅显示来自特定数据库的表

SELECT TABLE_NAME 
FROM [<DATABASE_NAME>].INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE'

Or,

SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE' 
    AND TABLE_CATALOG='dbName' --(for MySql, use: TABLE_SCHEMA='dbName' )

PS: SQL Server 2000:

SELECT * FROM sysobjects WHERE xtype='U' 
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'