Two Methods for querying the number of table fields in MySQL

Source: Internet
Author: User

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.

 
 
  1. SQL code
  2. Mysql> desc ysks;
  3. + ------- + --------------- + -----
  4. | Field | Type | Null
  5. + ------- + --------------- + -----
  6. | Ticket No. | int (11) | YES
  7. | Amount | decimal (10, 2) | YES
  8. | Received | decimal (10, 2) | YES
  9. | Date | bigint (20) | YES
  10. | Name | varchar (10) | YES
  11. | Balance | decimal (10, 2) | YES
  12. | Remarks | varchar (10) | YES
  13. | Product name | varchar (10) | YES
  14. + ------- + --------------- + -----
  15. 8 rows in set (0.06 sec)
  16.  
  17. Mysql> select FOUND_ROWS ();
  18. + -------------- +
  19. | FOUND_ROWS () |
  20. + -------------- +
  21. | 8 |
  22. + -------------- +
  23. 1 row in set (0.06 sec)
  24.  
  25. Mysql>
  26.  

Method 2: Use the system table information_schema. 'columns '(supported by MySQL 5 or later)

 
 
  1. SQL code   
  2. mysql> select count(*) from information_schema.`COLUMNS`  
  3.     -> where TABLE_SCHEMA='csdn' 
  4.     -> and TABLE_NAME='ysks';  
  5. +----------+  
  6. | count(*) |  
  7. +----------+  
  8. |        8 |  
  9. +----------+  
  10. 1 row in set (0.06 sec)  
  11.  
  12. mysql> 
  13.    
  14.  

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.