MySQL 中的列名和表名是否区分大小写?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2009005/
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
Are column and table name case sensitive in MySQL?
提问by shin
If I have a column names called category_id
and Category_Id
, are they different?
如果我有一个名为category_id
and的列名Category_Id
,它们是否不同?
And if I have table called category
and Category
, are they different?
如果我有一个叫做category
and 的表Category
,它们有什么不同吗?
回答by Seva Alekseyev
On Unix, table names are case sensitive. On Windows, they are not. Fun, isn't it? Kinda like their respective file systems. Do you think it's a coincidence?
在 Unix 上,表名区分大小写。在 Windows 上,它们不是。有趣,不是吗?有点像他们各自的文件系统。你认为这是巧合吗?
In other words, if you are planning on deploying on a Linux machine, better test your SQL against a Linux-based MySQL too, or be prepared for mysterious "table not found" errors at prod time. VMs are cheap these days.
换句话说,如果您计划在 Linux 机器上部署,最好也针对基于 Linux 的 MySQL 测试您的 SQL,或者在生产时为神秘的“找不到表”错误做好准备。现在虚拟机很便宜。
Field (column) names are case-insensitive regardless.
无论如何,字段(列)名称不区分大小写。
EDIT: we're talking about the operating system on the MySQL servermachine, not client.
编辑:我们谈论的是 MySQL服务器机器上的操作系统,而不是客户端。
回答by Anitha.y
From the MySQL documentation:
从 MySQL文档:
database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix. One notable exception is Mac OS X, which is Unix-based but uses a default file system type (HFS+) that is not case sensitive.
数据库和表名在 Windows 中不区分大小写,而在大多数 Unix 版本中区分大小写。一个值得注意的例外是 Mac OS X,它基于 Unix,但使用不区分大小写的默认文件系统类型 (HFS+)。
and
和
Column and index names are not case sensitive on any platform, nor are column aliases.
列名和索引名在任何平台上都不区分大小写,列别名也不区分大小写。
回答by Pekka
For database and table names, it depends on the underlying operating system. See 8.2.2. Identifier Case Sensitivity
对于数据库和表名,它取决于底层操作系统。见8.2.2。标识符区分大小写
回答by Vincent Ramdhanie
回答by Thomas Touzimsky
Strangely enough it seemsto be case sensitive in the MySQL Workbench even on Windows.
奇怪的是,即使在 Windows 上,它似乎也在 MySQL Workbench 中区分大小写。
We just tried to alter the results of a SELECT statement but the Workbench didn't let us, complaining that our query did not include the table's primary key (which it did but in lower-case) so the result was read-only. Running the same query with the primary key in proper case (ID instead of id) would let us edit the results as expected.
我们只是试图改变 SELECT 语句的结果,但工作台没有让我们,抱怨我们的查询不包括表的主键(它包括但小写)所以结果是只读的。在适当的情况下使用主键(ID 而不是 id)运行相同的查询将让我们按预期编辑结果。