tags:

views:

27

answers:

6

Hi

I want to write a query to get the names of tables of a specific database, but I don't know how can write it.

I want to execute this query for MySql.

+1  A: 

http://www.devdaily.com/blog/post/mysql/list-tables-in-mysql-database

Boris Modylevsky
thanks for all.
na.fa
+1  A: 

If you have the correct permissions you can use the following SQL

show tables;

Link to documentation

That will return a single column from the database with a list of tables in it.

The field name should be Tables_in_databasename

Re0sless
+1  A: 

this command will give you the list of tables.

use mine;

show tables;

George Lambert
+1  A: 

Here is a better guide, that shows a C# method for getting table names from a MySQL Database.

If you need help in creating a MySQL Connection string here is an example

Nix
+2  A: 

Download mysql connector from here: http://dev.mysql.com/downloads/connector/net/

Use this code:

using MySql.Data.MySqlClient;

string myConnectionString = "SERVER=localhost;" +
                            "DATABASE=mydatabase;" +
                            "UID=user;" +
                            "PASSWORD=mypassword;";

MySqlConnection connection = new MySqlConnection(myConnectionString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "SHOW TABLES;";
MySqlDataReader Reader;
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
    string row = "";
    for (int i = 0; i < Reader.FieldCount; i++)
        row += Reader.GetValue(i).ToString() + ", ";
    Console.WriteLine(row);
}
connection.Close();
Andreas Rehm
+1  A: 

another way by using the ANSI INFORMATION_SCHEMA view

   SELECT * 
   FROM INFORMATION_SCHEMA.TABLES
   WHERE TABLE_TYPE = 'BASE TABLE'
SQLMenace