MySQL 从数据库中获取表名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4645456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get table names from a database
提问by Syed Abdul Rahman
I've searched through a bunch of websites and I have not come across any code or tutorial which has gone through the specifics of obtaining the table names from a single database.
我搜索了一堆网站,但没有遇到任何代码或教程,这些代码或教程已经完成了从单个数据库获取表名的细节。
Assuming I have 4 databases and I want the names of all the tables within the database called mp21
, what query can I use?
假设我有 4 个数据库并且我想要数据库中所有表的名称,mp21
我可以使用什么查询?
回答by stian.net
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
回答by Richard H
In MySQL this will list all databases:
在 MySQL 中,这将列出所有数据库:
show databases;
For each of these you can do:
对于其中的每一个,您可以执行以下操作:
use <database_name>;
and then
进而
show tables;
回答by Sachin Shanbhag
In SQL SERVER, you can just use -
在 SQL SERVER 中,您可以使用 -
select * from sys.tables
回答by Ghyath Serhal
use mp21
SELECT name FROM dbo.sysobjects WHERE xtype = 'U'
回答by rajesh Kumar
I used this query:
我使用了这个查询:
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
It gives me table name as well as sysDiagram(database diagram generated for that database)
它给了我表名以及 sysDiagram(为该数据库生成的数据库图)
回答by AYRM1112013
Here is the MySQL query you asked.
这是您询问的 MySQL 查询。
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='mp21'
回答by Rami Shareef
if you are asking about .net code then You need SMO:
如果您询问 .net 代码,那么您需要SMO:
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
public static List<Table> GetTables(string connection, string databaseName)
{
if (String.IsNullOrEmpty(connection))
throw new ArgumentException("connection is null or empty.", "connection");
Server srv = getServer(connection);
return srv.Databases[databaseName].Tables.Cast<Table>().ToList();
}