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


当前回答

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

SQL Server 2012

其他回答

USE YourDBName
GO 
SELECT *
FROM sys.Tables
GO

OR

USE YourDBName
GO
SELECT * FROM INFORMATION_SCHEMA.TABLES 
GO
SELECT sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U' 
SELECT * FROM information_schema.tables
where TABLE_TYPE = 'BASE TABLE'

SQL Server 2012

使用SELECT * FROM INFORMATION_SCHEMA。COLUMNS还显示所有表和相关列。

请用这个。你会得到表名和模式名:

SELECT SYSSCHEMA.NAME, SYSTABLE.NAME
FROM SYS.tables SYSTABLE
INNER JOIN SYS.SCHEMAS SYSSCHEMA
ON SYSTABLE.SCHEMA_ID = SYSSCHEMA.SCHEMA_ID