Mysql用sql语句创建表格或查询记录时,出现字段名中带斜杠的情况,如果用平时的写法要么插入失败要么查询结果不对
如:
create table test(name/id char(20) not null);
mysql会报语法错误
mysql> create table test(name/id char(20) not null);
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 '/id char(20) not null)' at line 1
这个时候需要将字段名用 反单引号 ` 标记,即tab键上方的那个键,不是单引号 ‘ !
create table test(`name/id` char(20) not null);
创建成功!
mysql> create table test(`name/id` char(20) not null);
Query OK, 0 rows affected (0.17 sec)