COLUMN_NAME을 사용하여 데이터베이스에서 특정 열이 포함된 테이블을 찾습니다. 먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable -> ( -> CustomerId int, -> CustomerName varchar(20), -> CustomerCountryName varchar(100) -> ); Query OK, 0 rows affected (1.05 sec)
다음은 특정 열 "'CustomerCountryName'"이 있는 테이블을 찾는 쿼리입니다. −
mysql> select *from information_schema.columns WHERE COLUMN_NAME = 'CustomerCountryName';
출력
이것은 다음과 같은 출력을 생성합니다 -
+---------------+--------------+--------------+---------------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+-----------------+--------------+------------+-------+---------------------------------+----------------+-----------------------+-------+ | TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME |ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE |CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH |NUMERIC_PRECISION | UMERIC_SCALE | DATETIME_PRECISION |CHARACTER_SET_NAME | COLLATION_NAME | COLUMN_TYPE | COLUMN_KEY | EXTRA | PRIVILEGES | COLUMN_COMMENT | GENERATION_EXPRESSION | SRS_ID | +---------------+--------------+--------------+---------------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+-----------------+--------------+------------+-------+---------------------------------+----------------+-----------------------+-------+ | def | sample | demotable189 | CustomerCountryName | 4 | NULL |YES | varchar | 100 | 300 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(100) | | |select,insert,update,references | | | NULL | | def | web | DemoTable | CustomerCountryName | 4 | NULL |YES | varchar | 20 | 60 | NULL | NULL |NULL | utf8 | utf8_unicode_ci | varchar(20) | | |select,insert,update,references | | | NULL | | def | web | DemoTable | CustomerCountryName | 3 | NULL |YES | varchar | 100 | 300 | NULL | NULL |NULL | utf8 | utf8_unicode_ci | varchar(100) | | |select,insert,update,references | | | NULL | +---------------+--------------+--------------+---------------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+--------------------+-----------------+--------------+------------+-------+---------------------------------+----------------+-----------------------+-------+ 3 rows in set (0.68 sec)
위에서 "CustomerCountryName" 열이 3개의 테이블에 있는 것을 볼 수 있습니다.