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

특정 열이 있는 MySQL 데이터베이스에서 모든 테이블을 가져옵니다. 예를 들어 xyz라고 가정해 보겠습니다.

<시간/>

"웹" 데이터베이스가 있고 특정 열 'StudentFirstName'이 있는 모든 테이블을 가져와야 한다고 가정해 보겠습니다.

이를 위해 아래는 쿼리입니다 -

mysql> select myColumnName.table_name from
information_schema.columns myColumnName
where myColumnName.column_name = 'StudentFirstName' and table_schema='web';

이것은 다음과 같은 출력을 생성합니다 -

+---------------+
| TABLE_NAME    |
+---------------+
| demotable109  |
| demotable297  |
| demotable335  |
| demotable395  |
| demotable418  |
| demotable425  |
| demotable436  |
+---------------+
7 rows in set (0.14 sec)

따라서 위의 표에는 "StudentFirstName"이라는 열 이름 중 하나가 있습니다.

열 이름 'StudentFirstName'을 찾기 위해 테이블의 설명을 확인합시다 -

mysql> desc demotable297;

이렇게 하면 열 이름 중 하나를 "StudentFirstName" -

으로 표시하는 다음 출력이 생성됩니다.
+------------------+--------------+------+-----+---------+-------+
| Field            | Type         | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+-------+
| StudentId        | int(11)      | YES  |     | NULL    |       |
| StudentFirstName | varchar(100) | YES  |     | NULL    |       |
| StudentLastName  | varchar(100) | YES  |     | NULL    |       |
+------------------+--------------+------+-----+---------+-------+
3 rows in set (0.01 sec)