0

I have created two table by generating via forms. My question is although second table's foreign key appears on phpmyadmin it doesnt have that same value with the first table's primary key.
currently foreign key has all zero values in all of the rows.
Table codes:

$sql2='CREATE TABLE IF NOT EXISTS CourseList(
Course_id  int NOT NULL auto_increment,
CourseCode varchar(10) NULL,
CourseName varchar(40) NULL,
Instructor varchar(40) NULL,
PRIMARY KEY(Course_id)
)';

$sql3='CREATE TABLE IF NOT EXISTS StudentAccess(              
StudentNumber varchar(12) NOT NULL,
StudentFirstName varchar(15) NOT NULL,
Course_id int NOT NULL,
FOREIGN KEY (Course_id) REFERENCES CourseList(Course_id) ON DELETE CASCADE
)';

how should i write foreign key code to link "StudentAccess's Course_id" to "CourseList's Course_id"??

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by SOB224
0

i still can't make it. :(
somehow FOREIGN KEY (Course_id) REFERENCES CourseList(Course_id) ON DELETE CASCADE doesn't work.

it also work but StudentAccess table's Course_id is all zeros.
i also tried Course_id int NOT NULL REFERENCES CourseList(Course_id) but it doesn't work too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.