I want to write a program that can show the user a list of tables in the database and also show the descriptions of those tables. So can I do a "select * from system_table" or something like that?
+5
A:
This will give you a list of tables:
show tables;
To describe each table:
describe table_name;
To get both at the same time try:
SELECT * FROM DOMAIN.TABLES WHERE TYPE = 'TABLE'
SELECT * FROM DOMAIN.COLUMNS WHERE TABLETYPE = 'TABLE'
The results are similar to MySql show and describe statements
photographique
2009-10-01 01:08:13
What is the domain and where would you find this information?
Weston Goodwin
2009-10-02 01:13:23
+1
A:
In addition to show tables
, MySQL 5.0+ also supports the INFORMATION_SCHEMA
meta-database:
SELECT table_name, table_comment FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'db_name';
information_schema.tables
also has other information in it, if you're curious.
Note that if you didn't provide a comment when you created the table and use InnoDB, it will fill the table_comment column with unnecessary data, such as the InnoDB space reserved for this table or the foreign key constraints.
R. Bemrose
2009-10-01 02:55:14
I am running an older version of mysql 4.1x so this will not work for me, but thank you for the suggestion.
Weston Goodwin
2009-10-02 01:14:19