We often encounter problems when querying table fields in MySQL. The following describes in detail how to query table fields in MySQL.
In mysql, how does one query the number of fields in a table?
Method 1: directly in your program
Desc tablename
Then, the total number of rows is the number of fields.
- SQL code
- Mysql> desc ysks;
- + ------- + --------------- + -----
- | Field | Type | Null
- + ------- + --------------- + -----
- | Ticket No. | int (11) | YES
- | Amount | decimal (10, 2) | YES
- | Received | decimal (10, 2) | YES
- | Date | bigint (20) | YES
- | Name | varchar (10) | YES
- | Balance | decimal (10, 2) | YES
- | Remarks | varchar (10) | YES
- | Product name | varchar (10) | YES
- + ------- + --------------- + -----
- 8 rows in set (0.06 sec)
-
- Mysql> select FOUND_ROWS ();
- + -------------- +
- | FOUND_ROWS () |
- + -------------- +
- | 8 |
- + -------------- +
- 1 row in set (0.06 sec)
-
- Mysql>
-
Method 2: Use the system table information_schema. 'columns '(supported by MySQL 5 or later)
- SQL code
- mysql> select count(*) from information_schema.`COLUMNS`
- -> where TABLE_SCHEMA='csdn'
- -> and TABLE_NAME='ysks';
- +----------+
- | count(*) |
- +----------+
- | 8 |
- +----------+
- 1 row in set (0.06 sec)
-
- mysql>
-
-
In-depth parsing MySQL Association Table Creation
View MySQL database commands
How to display MYSQL table information
Three Common MySQL table creation statements
MySQL connection Query