前言
最近最近在学MySQL,因为CTF之类有用到,其实也是必学的,只是时间提前了一点。。
问题
尝试创建外键时报错:
mysql> create table course(cid bigint auto_increment primary key, cname char(10), teacher_id bigint, constraint fk_course_tid foreign key ("teacher_id") references teacher('tid') )engine=innodb default charset=utf8; 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 '"teacher_id") references teacher('tid'))engine=innodb default charset=utf8' at line 1 ------------------------------ mysql> create table course(cid bigint auto_increment primary key, cname char(10), teacher_id bigint, constraint fk_course_tid foreign key (`teacher_id`) references teacher('tid') )engine=innodb default charset=utf8; 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 ''tid'))engine=innodb default charset=utf8' at line 1
其实中间经历一堆问题 #(流汗滑稽) ,只是这个比较隐秘,一直提示语法错误,都是在"
和'
附近,
以为打成中文的,看了下确实是英文的,郁闷。。。
思考片刻,发现还有`
这个符号,试了一下,通过了
这啥玩意儿 #(不高兴)
mysql> create table course(cid bigint auto_increment primary key,cname char(10),teacher_id bigint,constraint fk_course_tid foreign key (`teacher_id`) references teacher(`tid`))engine=innodb default charset=utf8; Query OK, 0 rows affected (0.03 sec)