显示一个表的结构的MySQL查询
要显示一个表的结构,以下为语句语法 −
show create table yourTableName;
我们先创建一个表 −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeFirstName varchar(100), -> EmployeeLastName varchar(100), -> EmployeeAge int, -> isMarried tinyint(1), -> EmployeeAddress varchar(100), -> EmployeeCountryName varchar(100) -> ); Query OK, 0 rows affected (0.62 sec)
以下为显示结构的查询 −
mysql> show create table DemoTable;
输出
这将生成以下输出 −
+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DemoTable | CREATE TABLE `DemoTable` ( `Id` int(11) NOT NULL AUTO_INCREMENT, `EmployeeFirstName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `EmployeeLastName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `EmployeeAge` int(11) DEFAULT NULL, `isMarried` tinyint(1) DEFAULT NULL, `EmployeeAddress` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, `EmployeeCountryName` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci | +--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
广告