Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a database in mysql name "data". In data I have 3 table which name "a_table", "b_table","c_table".
How I list the name of table in database "data"?
Please help. Thanks.
Posted
Comments
Arasappan 31-Jul-15 1:36am    
Please quit bit clear what do u want.
Member 10390715 31-Jul-15 2:16am    
Yes. I want to list table name in mysql database

1 solution

CSS
SHOW TABLES IN data;

Try the MySQL Manual, it is full of useful information.

https://dev.mysql.com/doc/refman/5.0/en/show-tables.html
 
Share this answer
 
Comments
Member 10390715 31-Jul-15 2:48am    
Hello, I use this query:
SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%nh%'
And mysql return me the result I want.
Now I make a fuction in C# like this to get table name return into combobox. But it not work.
What wrong with it?
<pre lang="c#">
string myConnection = "Server=localhost;Database=data;Port=3306;User ID=root;Password=;Charset=utf8";
string query = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%nh%'";
conDatabase = new MySqlConnection(myConnection);
MySqlCommand cmdDataBase = new MySqlCommand(query, conDatabase);
MySqlDataReader myReader;
try
{
conDatabase.Open();
myReader = cmdDataBase.ExecuteReader();
cb_data_name.Items.Clear();
if (myReader.HasRows == true)
{
while (myReader.Read())
{
cb_chon.Items.Add((string)myReader[0]);
}
}
}
catch
{

}
</pre>
Michael_Davies 31-Jul-15 3:05am    
Here's the thing; You did not ask this question in your original statement, how can anyone provide you with help that is relevant if you do not ask the full question, you do know how to get table names that is not the problem.

Have you walked through with the debugger and if so does it enter the read loop at least once. You might notice that none of your tables are LIKE %nh% as you say their names are a_table, b_table and c_table, unless I spelt those names incorrectly and missed the nh out!

Beware: you are selecting from the INFORMATION_SCHEMA so your SELECT will pull ALL tables matching the LIKE not just for the database data.
Member 10390715 31-Jul-15 4:50am    
yes. I just want list table name in one database. How can I fix it?
Michael_Davies 31-Jul-15 4:53am    
And the solution I provided already?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900