通过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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值