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


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

Syntax

SHOW COLUMNS FROM db_name.tab_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 table named ‘arena’ stored in mysql ‘database’ −

mysql> SHOW COLUMNS FROM mysql.arena\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.00 sec)

Updated on: 20-Jun-2020

42 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements