问题

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



解决方法

SQL Server 2005,2008,2012或2014:

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' )

PS:对于SQL Server 2000:

SELECT * FROM sysobjects WHERE xtype='U' 



相关问题推荐