Check the DDL or Structure of columns in table in MySQL
Check Structure of table with Describe command
mysql> use world
mysql> desc city;
+-------------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+----------+------+-----+---------+----------------+
| ID | int | NO | PRI | NULL | auto_increment |
| Name | char(35) | NO | | | |
| CountryCode | char(3) | NO | MUL | | |
| District | char(20) | NO | | | |
| Population | int | NO | | 0 | |
+-------------+----------+------+-----+---------+----------------+
5 rows in set (0.01 sec)
Check Data definition language (DDL) of table
mysql> show create table city;
----------------------------------------------------------------------------
| Table | Create Table
----------------------------------------------------------------------------
| city | CREATE TABLE `city` (
`ID` int NOT NULL AUTO_INCREMENT,
`Name` char(35) NOT NULL DEFAULT '',
`CountryCode` char(3) NOT NULL DEFAULT '',
`District` char(20) NOT NULL DEFAULT '',
`Population` int NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `CountryCode` (`CountryCode`),
CONSTRAINT `city_ibfk_1` FOREIGN KEY (`CountryCode`) REFERENCES `country` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=4080 DEFAULT CHARSET=latin1 |
----------------------------------------------------------------------------
1 row in set (0.01 sec)
Could someone please explain to me what is the meaning of KEY that comes after the PRIMARY KEY in DDL (this one -> KEY `CountryCode` (`CountryCode`)) , what does it do? Thanks in advance.
LikeLike