mysql query “SHOW COLUMNS FROM table like 'colmunname'”:questions

后端 未结 4 766
鱼传尺愫
鱼传尺愫 2021-02-14 14:27

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 colu

相关标签:
4条回答
  • 2021-02-14 14:56

    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.

    0 讨论(0)
  • 2021-02-14 14:56

    maybe this: SHOW COLUMNS FROM accounts LIKE'id'

    0 讨论(0)
  • 2021-02-14 15:00

    Where is used to get an exact match where as like is used to get a wider range of columns using wildcards.

    SHOW COLUMNS FROM table like 'my%";
    

    The above will find all columns that begin with my.

    Where as with a where clause you cannot use wildcards and will only get returned exact matches. Obviously you could use where with between,> or < etc in other cases which would give you a wider range but still not allow you to use any wildcards.

    0 讨论(0)
  • 2021-02-14 15:07

    SHOW ... LIKE behaves like the use of the LIKE operator in the WHERE clause of a common query:

    SHOW COLUMNS Syntax

    SHOW [FULL] COLUMNS {FROM | IN} tbl_name [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]

    SHOW COLUMNS displays information about the columns in a given table. It also works for views. The LIKE clause, if present, indicates which column names to match. The WHERE clause can be given to select rows using more general conditions, as discussed in Section 21.32, “Extensions to SHOW Statements”.

    Emphasis by me.

    0 讨论(0)
提交回复
热议问题