![]() |
|
|
#1 |
|
Administrator
Join Date: Jun 2004
Posts: 383
|
3.4 Getting Information About Databases and Tables
What if you forget the name of a database or table, or what the structure of a given table is (for example, what its columns are called)? MySQL addresses this problem through several statements that provide information about the databases and tables it supports.
You have already seen SHOW DATABASES, which lists the databases managed by the server. To find out which database is currently selected, use the DATABASE() function: mysql> SELECT DATABASE();+------------+| DATABASE() |+------------+| menagerie |+------------+If you haven't selected any database yet, the result is NULL (or the empty string before MySQL 4.1.1). To find out what tables the current database contains (for example, when you're not sure about the name of a table), use this command: mysql> SHOW TABLES;+---------------------+| Tables in menagerie |+---------------------+| event || pet |+---------------------+If you want to find out about the structure of a table, the DESCRIBE command is useful; it displays information about each of a table's columns: mysql> DESCRIBE pet;+---------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+---------+-------------+------+-----+---------+-------+| name | varchar(20) | YES | | NULL | || owner | varchar(20) | YES | | NULL | || species | varchar(20) | YES | | NULL | || sex | char(1) | YES | | NULL | || birth | date | YES | | NULL | || death | date | YES | | NULL | |+---------+-------------+------+-----+---------+-------+Field indicates the column name, Type is the data type for the column, NULL indicates whether the column can contain NULL values, Key indicates whether the column is indexed, and Default specifies the column's default value. If you have indexes on a table, SHOW INDEX FROM tbl_name produces information about them. |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Populating MySQL Memory Tables | martman | General | 1 | 11-24-2004 08:26 AM |
| 1.2.4 How Big MySQL Tables Can Be | Administrator | Documentation | 3 | 10-21-2004 12:38 AM |
| 2 Installing MySQL | Administrator | Documentation | 103 | 06-09-2004 02:53 AM |
| 1.8 MySQL Standards Compliance | Administrator | Documentation | 21 | 06-08-2004 03:18 AM |
| 1.2.2 The Main Features of MySQL | Administrator | Documentation | 0 | 06-08-2004 01:55 AM |