1、錯誤描述
1 queries executed, 0 success, 1 errors, 0 warnings 查詢:create table example3( id Primary key, stu_id int, constraint c_fk foreign key(stu_id,course_id) references example2(stu_id,cour... 錯誤代碼: 1064 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 'Primary key, stu_id int, constraint c_fk foreign key(stu_id,course_i' at line 2 執行耗時 : 0 sec 傳送時間 : 0 sec 總耗時 : 0 sec
CREATE TABLE example1( stu_id INT PRIMARY KEY, stu_name VARCHAR(20), stu_sex BOOLEAN ); CREATE TABLE example2( stu_id INT, course_id INT, grade FLOAT, PRIMARY KEY(stu_id,course_id) ); CREATE TABLE example3( id PRIMARY KEY, stu_id INT, CONSTRAINT c_fk FOREIGN KEY(stu_id,course_id) REFERENCES example2(stu_id,course_id) );
在新建example3表時,未給id數據類型
3、解決辦法
CREATE TABLE example3( id INT PRIMARY KEY, stu_id INT, CONSTRAINT c_fk FOREIGN KEY(stu_id,course_id) REFERENCES example2(stu_id,course_id) );
1 queries executed, 0 success, 1 errors, 0 warnings 查詢:create table example3( id int Primary key, stu_id int, constraint c_fk foreign key(stu_id,course_id) references example2(stu_id,... 錯誤代碼: 1072 Key column 'course_id' doesn't exist in table 執行耗時 : 0 sec 傳送時間 : 0 sec 總耗時 : 0.001 sec