Home > Software engineering >  how to get only name of columns in mysql table?
how to get only name of columns in mysql table?

Time:02-06

i saw this post MySQL query to get column names? i try to use this code `table name` or DESCRIBE `table name` or SHOW COLUMNS FROM `table name` but return me also a datatype and more in this mode

id  int NO auto_increment

i want only a name id is possible have it ?? thanks somtime is possible bypass qualitystandard ?? please

CodePudding user response:

use the tables from information_schema to get the meta data of your table:

SELECT COLUMN_NAME
  FROM INFORMATION_SCHEMA.COLUMNS
  WHERE table_name = 'tbl_name'

For more information see https://docs.oracle.com/cd/E19078-01/mysql/mysql-refman-5.0/information-schema.html#columns-table

CodePudding user response:

If you don't like the default output of the SHOW commands, you can get anything you want from the INFORMATION_SCHEMA tables (which is where the SHOW commands get their data too).

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?;
  •  Tags:  
  • Related