Are column and table name case sensitive in MySQL?

后端 未结 5 962
遥遥无期
遥遥无期 2020-11-28 09:04

If I have a column names called category_id and Category_Id, are they different?

And if I have table called category and

相关标签:
5条回答
  • 2020-11-28 09:31

    For database and table names, it depends on the underlying operating system. See 8.2.2. Identifier Case Sensitivity

    0 讨论(0)
  • 2020-11-28 09:34

    You might find this necessary to read. It is possible to set the case sensitivity in MySQL but it really is only a problem when you work in multiple environments.

    0 讨论(0)
  • 2020-11-28 09:38

    Strangely enough it seems to be case sensitive in the MySQL Workbench even on Windows.

    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.

    0 讨论(0)
  • 2020-11-28 09:44

    From the MySQL documentation:

    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.

    and

    Column and index names are not case sensitive on any platform, nor are column aliases.

    0 讨论(0)
  • 2020-11-28 09:51

    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?

    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.

    Field (column) names are case-insensitive regardless.

    EDIT: we're talking about the operating system on the MySQL server machine, not client.

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