SHOW COLUMNS

Description

Returns the list of columns in a table. If the table does not exist, an exception is thrown.

Syntax

  1. SHOW COLUMNS table_identifier [ database ]

Parameters

  • table_identifier

    Specifies the table name of an existing table. The table may be optionally qualified with a database name.

    Syntax: { IN | FROM } [ database_name . ] table_name

    Note: Keywords IN and FROM are interchangeable.

  • database

    Specifies an optional database name. The table is resolved from this database when it is specified. When this parameter is specified then table name should not be qualified with a different database name.

    Syntax: { IN | FROM } database_name

    Note: Keywords IN and FROM are interchangeable.

Examples

  1. -- Create `customer` table in `salesdb` database;
  2. USE salesdb;
  3. CREATE TABLE customer(
  4. cust_cd INT,
  5. name VARCHAR(100),
  6. cust_addr STRING);
  7. -- List the columns of `customer` table in current database.
  8. SHOW COLUMNS IN customer;
  9. +---------+
  10. | col_name|
  11. +---------+
  12. | cust_cd|
  13. | name|
  14. |cust_addr|
  15. +---------+
  16. -- List the columns of `customer` table in `salesdb` database.
  17. SHOW COLUMNS IN salesdb.customer;
  18. +---------+
  19. | col_name|
  20. +---------+
  21. | cust_cd|
  22. | name|
  23. |cust_addr|
  24. +---------+
  25. -- List the columns of `customer` table in `salesdb` database
  26. SHOW COLUMNS IN customer IN salesdb;
  27. +---------+
  28. | col_name|
  29. +---------+
  30. | cust_cd|
  31. | name|
  32. |cust_addr|
  33. +---------+