如何创建一个带有像a^b名称的表以及同一列名称?\n名称?


要创建带有此类名称的表,我们必须使用引号字符。引号可以是单引号或双引号,具体取决于 ANSI_QUOTES SQL 模式。 

如果此模式是已禁用,则标识符引号字符是反引号 (“`”)。考虑以下示例,我们在其中创建了一个名为‘select’的表 −

mysql> Create table `a^b`(`a^b` int);
Query OK, 0 rows affected (0.19 sec)

mysql> Create table "a^g"("a^g" int);
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near '"a^g" ("a^g" int)' at line 1

如果此模式已启用,则我们可以使用反引号 (“`”) 和双引号 (“”) 作为引号字符。考虑以下示例,我们在其中使用这两个引号字符创建了具有上面名称的表,此前启用了此模式 −

mysql> Set sql_mode = 'ANSI_Quotes';
Query OK, 0 rows affected (0.03 sec)

mysql> Create table "a^d"("a^d" int);
Query OK, 0 rows affected (0.21 sec)

mysql> Create table `a^e`(`a^e` int);
Query OK, 0 rows affected (0.14 sec)

更新于: 2020 年 6 月 22 日

84 次浏览

开启你的 事业

通过完成课程取得认证

开始
广告
© . All rights reserved.