Get List of Columns from Another Database Table in SQL



It can be done with the SHOW COLUMNS statement. Its Syntax would be as follows:

Syntax

SHOW COLUMNS FROM tab_name IN db_name

Here, 

  • tab_name is the name of the table from which we want to see the list of columns.
  • Db_name is the name of the database, in which the table is stored

Example

In the example, we are currently using the database ‘query’ and getting the list of columns
from a table named ‘arena’ stored in MySQL ‘database’:

mysql> SHOW COLUMNS FROM arena IN mysql\G
*************************** 1. row ***************************
  Field: id
   Type: int(10) unsigned zerofill
   Null: NO
    Key: PRI
Default: NULL
Extra  : auto_increment
*************************** 2. row ***************************
  Field: Photo
   Type: blob
   Null: YES
    Key:
Default: NULL
  Extra:
2 rows in set (0.08 sec)
Updated on: 2020-02-12T05:24:22+05:30

81 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements