You have previously 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 |
+------------+
NULL
.To find out what tables the default database contains (for example, when you are not sure about the name of a table), use this command:
mysql>SHOW TABLES;
+---------------------+
| Tables_in_menagerie |
+---------------------+
| event |
| pet |
+---------------------+
The name of the column in the output produced by this statement is
always
Tables_in_db_name
,where
db_name
is the name of thedatabase. See Section 12.5.4.25, “
SHOW TABLES
Syntax”, for more information.If you want to find out about the structure of a table, the
DESCRIBE
command is useful; it displaysinformation 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 containNULL
values, Key
indicateswhether the column is indexed, and
Default
specifies the column's default value.
Extra
displays special information about columns; for example, if a
column was created with the
AUTO_INCREMENT
option, this is shown here.
No comments:
Post a Comment