Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql query "SHOW COLUMNS FROM table like 'colmunname'":questions

Tags:

sql

mysql

I have a question about SHOW COLUMNS FROM table like 'column name'". I have already tried some tests for some times, it seems be similar like "where column name='column'.

However, I just would like to confirm thank u very much in advance.

Also, I'd like to say, why cannot I use SHOW COLUMNS FROM table = 'columnname' ?

like image 855
martinwang1985 Avatar asked Jul 31 '14 08:07

martinwang1985


1 Answers

It's more like

WHERE column_name LIKE 'column name'

Since it uses LIKE, you can put wildcard patterns in the parameter, e.g.

SHOW COLUMNS FROM table LIKE '%id'

will find all columns that end in id.

If there are no wildcard characters, then LIKE is equivalent to =.

If you don't want to use LIKE, you can use WHERE:

SHOW COLUMNS FROM table WHERE field = 'column name';

In the SHOW COLUMNS output, the field column contains the column names. The WHERE clause also permits testing other attributes, e.g.

SHOW COLUMNS FROM table WHERE type LIKE 'varchar%'

will find all VARCHAR columns.

like image 190
Barmar Avatar answered Sep 16 '22 14:09

Barmar