Error code: 1064, error code 1064
1. Error description
1 queries executed, 0 success, 1 errors, 0 warnings query: create table example3 (id Primary key, stu_id int, constraint c_fk foreign key (stu_id, course_id) references example2 (stu_id, cour... error code: 1064You 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 execution time: 0 sec Transfer Time: 0 sec total time: 0 sec
2. Error cause
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) );
The id data type is not given when the example3 table is created.
3. Solution
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 query: create table example3 (id int Primary key, stu_id int, constraint c_fk foreign key (stu_id, course_id) references example2 (stu_id ,... error code: 1072Key column 'course _ id' doesn' t exist in table execution time: 0 sec Transfer Time: 0 sec total time consumed: 0.001 sec