테이블의 열 이름을 가져오는 구문은 다음과 같습니다. -
select column_name from information_schema.columns where table_schema='yourDatabaseName' and table_name=’yourTableName’;
먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable
(
EmployeeId int,
EmployeeFirstName varchar(20),
EmployeeLastName varchar(20),
EmployeeAge int,
EmployeeCountryName varchar(40),
IsMarried tinyint(1),
isActive ENUM('ACTIVE','INACTIVE')
);
Query OK, 0 rows affected (0.65 sec) 다음은 테이블의 열 이름을 가져오는 쿼리입니다. 여기에서 DemoTable의 열 이름을 가져옵니다. -
mysql> select column_name from information_schema.columns where table_schema='web' and table_name='DemoTable';
이것은 다음과 같은 출력을 생성합니다 -
+---------------------+ | COLUMN_NAME | +---------------------+ | EmployeeId | | EmployeeFirstName | | EmployeeLastName | | EmployeeAge | | EmployeeCountryName | | IsMarried | | isActive | +---------------------+ 7 rows in set (0.00 sec)