Home  >  Article  >  Database  >  How to query all fields of a table in mysql?

How to query all fields of a table in mysql?

青灯夜游
青灯夜游Original
2020-09-30 15:52:2415438browse

Mysql method of querying all fields of a table: Use the "SHOW FROM" statement with the FULL keyword to query. The syntax "SHOW FULL COLUMNS FROM table_name" can display all field information of the specified data table.

How to query all fields of a table in mysql?

mysql query all fields of table words

1. View all table names:

show tables [from db_name];

2. View field information

SHOW FULL COLUMNS FROM table_name

Get the following information
Field: Field name
Type: Field type
Collation: Character set (mysql 5.0 or above) )
Null: Can it be NULL
Key: Index (PRI, unique, index)
Default: Default value
Extra: Extra (whether auto_increment)
Privileges: Permissions
Comment: Remarks (available for mysql 5.0 and above)

mysql> create table teacher  # 创建teacher表
    -> (
    -> Id int (5) auto_increment not null primary key,
    -> name char(10) not null,
    -> address varchar(50) default 'No.1 Mid school',
    -> year date
    -> );
Query OK, 0 rows affected (0.02 sec)

mysql> show tables;
+------------------+
| Tables_in_school |
+------------------+
| teacher          |
+------------------+
1 row in set (0.00 sec)

mysql> show full columns from teacher;  # 显示teacher表的所有字段
+---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
| Field   | Type        | Collation         | Null | Key | Default         | Extra          | Privileges                      | Comment |
+---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
| Id      | int(5)      | NULL              | NO   | PRI | NULL            | auto_increment | select,insert,update,references |         |
| name    | char(10)    | latin1_swedish_ci | NO   |     | NULL            |                | select,insert,update,references |         |
| address | varchar(50) | latin1_swedish_ci | YES  |     | No.1 Mid school |                | select,insert,update,references |         |
| year    | date        | NULL              | YES  |     | NULL            |                | select,insert,update,references |         |
+---------+-------------+-------------------+------+-----+-----------------+----------------+---------------------------------+---------+
4 rows in set (0.01 sec)

mysql> drop table teacher;  # 删除teacher表
Query OK, 0 rows affected (0.03 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql>

Recommended tutorial: mysql video tutorial

The above is the detailed content of How to query all fields of a table in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn