https://dev.mysql.com/doc/refman/5.7/en/identifiers.html 官方文章摘要般卑,許多細(xì)節(jié)未錄武鲁,可訪問此頁面查看
identifiers
1.?MySQL中的某個(gè)對(duì)象的名字就叫做:identifier
MySQL中的對(duì)象有:database(數(shù)據(jù)庫), table(表), index(索引), column(列), alias(別名), view(視圖), stored procedure(存儲(chǔ)過程), partition(分區(qū)), tablespace(表空間),等等
數(shù)據(jù)庫對(duì)象的名稱就是它的標(biāo)識(shí)符。
2. 是否加引號(hào)的問題
標(biāo)識(shí)符identifier可以加引號(hào)也可以不加引號(hào)蝠检,但是如果有特殊字符或者保留字洞坑,必須加引號(hào)。(例外:A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted.))? ? ? ? ? ? ? ? ??
MySQL中語法中標(biāo)識(shí)符的引號(hào)是這樣的(?`)?,? 學(xué)名開單引號(hào)蝇率,也叫反引號(hào)(backtick)迟杂,在Tab鍵上方刽沾,對(duì)應(yīng)的ASCII碼十進(jìn)制為96,16進(jìn)制為0x60
比如,有個(gè)表名字叫做select排拷,這與MySQL的保留字select沖突侧漓,于是用開單引號(hào)將其引起來,如果不引起來监氢,MYSQL將把select視為保留字布蔗,這條語句執(zhí)行就會(huì)出錯(cuò)。所以浪腐,有MYSQL保留字作為字段的纵揍,必須加上開單引號(hào)來區(qū)分。
比如下面這個(gè)語句:
mysql> SELECT * FROM `select` WHERE `select`.id > 100
如果開啟了ANSI_QUOTES SQL模式议街,也可以用雙引號(hào)將其引起來:
mysql> CREATE TABLE "test" (col INT);
ERROR 1064: You have an error in your SQL syntax...
mysql> SET sql_mode='ANSI_QUOTES';
mysql> CREATE TABLE "test" (col INT);
Query OK, 0 rows affected (0.00 sec)
如果開啟ANSI_QUOTES模式泽谨,那么雙引號(hào)引起來的就做標(biāo)識(shí)符,字符串就必須用單引號(hào)引起來特漩,此時(shí)字符串不允許用雙引號(hào)引起來吧雹。The??mode causes the server to interpret double-quoted strings as identifiers. Consequently, when this mode is enabled, string literals must be enclosed within single quotation marks. They cannot be enclosed within double quotation marks.
3. 大寫、小寫字母的敏感性(case sensitivity)
https://dev.mysql.com/doc/refman/5.7/en/identifier-case-sensitivity.html
MySQL中涂身,數(shù)據(jù)庫(databases)對(duì)應(yīng)著directories within the data directory
數(shù)據(jù)庫中的每一張表(table)都對(duì)應(yīng)著??at least one file within the database directory (and possibly more, depending on the storage engine)
觸發(fā)器Triggers also correspond to files
P:這些文件最終還是要落實(shí)到操作系統(tǒng)上雄卷!
Consequently, the case sensitivity of the underlying operating system plays a part in the case sensitivity of database, table, and trigger names.?
操作系統(tǒng)的對(duì)大小寫的敏感性在數(shù)據(jù)庫的敏感性中扮演重要角色
在windows系統(tǒng)中 not case-sensitive的,到Linux系統(tǒng)中就變成case-sensitive
一個(gè)重要的例外就是macOS, which is Unix-based but uses a default file system type (HFS+) that is not case-sensitive. However, macOS also supports UFS volumes, which are case-sensitive just as on any Unix.?
注意
在同一條語句中指稱同一張表不要一會(huì)兒用大寫一會(huì)兒用小寫蛤售,盡管有些platform不是case-sensitive的
Although database, table, and trigger names are not case sensitive on some platforms, you should not refer to one of these using different cases within the same statement. The following statement would not work because it refers to a table both as?my_table and as?MY_TABLE:
mysql> SELECT* FROM my_table WHEREMY_TABLE.col=1;
表名數(shù)據(jù)庫名在硬盤(disk)上存儲(chǔ)情況是由lower_case_table_names?system 這個(gè)變量值決定的丁鹉,這個(gè)是在你starting?mysqld的時(shí)候設(shè)置的
lower_case_table_names?system 變量值,在UNIX系統(tǒng)中默認(rèn)為0悴能,在Windows系統(tǒng)中默認(rèn)為1揣钦,在macOS中默認(rèn)為2
4. 關(guān)鍵字和保留字
官網(wǎng)保留字地址 https://dev.mysql.com/doc/refman/5.7/en/keywords.html
5. 名字長(zhǎng)度限制
Identifiers are stored using Unicode (UTF-8)