如何使用 TSQL 获取数据库中所有表的列表?

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

答案

SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
SELECT TABLE_NAME 
FROM <DATABASE_NAME>.INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE'
SELECT TABLE_NAME 
FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE = 'BASE TABLE' 
    AND TABLE_CATALOG='dbName' --(for MySql, use: TABLE_SCHEMA='dbName' )
SELECT * FROM sysobjects WHERE xtype='U'
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'
SELECT * FROM INFORMATION_SCHEMA.TABLES
SELECT * FROM Sys.Tables
select * from sys.tables;
SELECT * FROM INFORMATION_SCHEMA.TABLES
SELECT * FROM sysobjects WHERE xtype='U'
USE YourDBName
GO 
SELECT *
FROM sys.Tables
GO
USE YourDBName
GO
SELECT * FROM INFORMATION_SCHEMA.TABLES 
GO
SELECT * FROM information_schema.tables
where TABLE_TYPE = 'BASE TABLE'
exec sp_msforeachtable 'print ''?'''
SELECT name 
FROM sysobjects 
WHERE xtype='U' 
ORDER BY name;

select * from sysobjects where xtype='U'

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