Computer >> 컴퓨터 >  >> 프로그램 작성 >> MySQL

테이블 구조를 표시하는 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)