MySQL query to display structure of a table


To display structure of a table, following is the syntax −

show create table yourTableName;

Let us first create a table −

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)

Here is the query to display structure −

mysql> show create table DemoTable;

This will produce the following output −

+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 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)
raja
Published on 11-Jul-2019 15:03:50
Advertisements