mysql 查询“SHOW COLUMNS FROM table like 'colmunname'”:问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25053726/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql query "SHOW COLUMNS FROM table like 'colmunname'":questions
提问by martinwang1985
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'
.
我有一个关于SHOW COLUMNS FROM table like 'column name'"
. 我已经尝试了一些测试,它似乎类似于“ 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'
?
另外,我想说,为什么我不能使用SHOW COLUMNS FROM table = 'columnname'
?
回答by Barmar
It's more like
它更像是
WHERE column_name LIKE 'column name'
Since it uses LIKE
, you can put wildcard patterns in the parameter, e.g.
由于它使用LIKE
,您可以在参数中放置通配符模式,例如
SHOW COLUMNS FROM table LIKE '%id'
will find all columns that end in id
.
将找到所有以id
.
If there are no wildcard characters, then LIKE
is equivalent to =
.
如果没有通配符,则LIKE
相当于=
.
If you don't want to use LIKE
, you can use WHERE
:
如果不想使用LIKE
,可以使用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
输出中,该field
列包含列名称。该WHERE
子句还允许测试其他属性,例如
SHOW COLUMNS FROM table WHERE type LIKE 'varchar%'
will find all VARCHAR
columns.
将找到所有VARCHAR
列。
回答by VMai
SHOW ... LIKE behaves like the use of the LIKE operator in the WHERE
clause of a common query:
SHOW ... LIKE 的行为类似于在WHERE
公共查询的子句中使用 LIKE 运算符:
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”.
显示 [完整] 列{来自 | IN} tbl_name [{FROM | IN} db_name] [LIKE '模式' | 哪里expr]
SHOW COLUMNS 显示有关给定表中列的信息。它也适用于视图。LIKE 子句(如果存在)指示要匹配的列名称。可以使用 WHERE 子句来使用更一般的条件选择行,如第 21.32 节“SHOW 语句的扩展”中所述。
Emphasis by me.
强调我。
回答by Varun Nath
Where is used to get an exact match where as like is used to get a wider range of columns using wildcards.
Where 用于获得精确匹配,而 like 用于使用通配符获得更广泛的列。
SHOW COLUMNS FROM table like 'my%";
The above will find all columns that begin with my.
以上将找到所有以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.
与 where 子句一样,您不能使用通配符,并且只会返回完全匹配。很明显,你可以在那里与使用between
,>
或<
在其他情况下,它会给你一个更广泛的范围内,但仍不允许你使用任何通配符等。
回答by ilgam
maybe this: SHOW COLUMNS FROM accounts LIKE'id'
也许是这样:从帐户中显示列 LIKE'id'