Home > Database > Mysql Tutorial > body text

How can I get a list of columns from a table in the database we are currently using?

WBOY
Release: 2023-09-16 23:37:02
forward
704 people have browsed it

How can I get a list of columns from a table in the database we are currently using?

This can be done using the SHOW COLUMNS statement. Its syntax is as follows -

Syntax

SHOW COLUMNS FROM tab_name
Copy after login

Here tab_name is the name of the table from which we want to view the column list.

Example

In example, we get the column list from the table named Student_info -

mysql> SHOW COLUMNS FROM Student_info\G
*************************** 1. row ***************************
  Field: studentid
   Type: int(11)
   Null: YES
    Key:
Default: NULL
  Extra:
*************************** 2. row ***************************
  Field: Name
   Type: varchar(40)
   Null: YES
    Key:
Default: NULL
  Extra:
*************************** 3. row ***************************
  Field: Address
   Type: varchar(20)
   Null: YES
    Key:
Default: NULL
  Extra:
*************************** 4. row ***************************
  Field: Subject
   Type: varchar(20)
   Null: YES
    Key:
Default: NULL
  Extra:
4 rows in set (0.06 sec)
Copy after login

The above is the detailed content of How can I get a list of columns from a table in the database we are currently using?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template