通过SQL查询获取特定数据库的所有表名?

本文翻译自:Get all table names of a particular database by SQL query?

I am working on application which can deal with multiple database servers like "MySQL" and "MS SQL Server". 我正在研究可以处理多个数据库服务器(如“ MySQL”和“ MS SQL Server”)的应用程序。

I want to get tables' names of a particular database using a general query which should suitable for all database types. 我想使用适合所有数据库类型的常规查询来获取特定数据库的表名。 I have tried following: 我尝试了以下方法:

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

But it is giving table names of all databases of a particular server but I want to get tables names of selected database only. 但是它给出了特定服务器的所有数据库的表名,但是我只想获取所选数据库的表名。 How can I restrict this query to get tables of a particular database? 如何限制此查询以获取特定数据库的表?


#1楼

参考:https://stackoom.com/question/gq6U/通过SQL查询获取特定数据库的所有表名


#2楼

Yes oracle is : 是的,oracle是:

select * from user_tables

That is if you only want objects owned by the logged in user/schema otherwise you can use all_tables or dba_tables which includes system tables. 就是说,如果您只希望登录user/schema拥有的对象,否则可以使用包括系统表的all_tablesdba_tables


#3楼

只需将DATABASE NAME放在INFORMATION_SCHEMA.TABLES前面:

select table_name from YOUR_DATABASE.INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE'

#4楼

USE DBName;
SELECT * FROM sys.Tables;

We can deal without GO in-place of you can use semicolon ; 我们可以在没有GO情况下处理您可以使用分号的情况; .


#5楼

Exec sp_MSforeachtable 'Select ''?'''

#6楼

select * from sys.tables
order by schema_id      --comments: order by 'schema_id' to get the 'tables' in 'object explorer order'
go

你可能感兴趣的:(通过SQL查询获取特定数据库的所有表名?)