943,918 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1830
  • PHP RSS
Jan 3rd, 2009
0

Foreign Key is different than primary key

Expand Post »
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:

php Syntax (Toggle Plain Text)
  1. $sql2='CREATE TABLE IF NOT EXISTS CourseList(
  2. Course_id int NOT NULL auto_increment,
  3. CourseCode varchar(10) NULL,
  4. CourseName varchar(40) NULL,
  5. Instructor varchar(40) NULL,
  6. PRIMARY KEY(Course_id)
  7. )';
  8.  
  9. $sql3='CREATE TABLE IF NOT EXISTS StudentAccess(
  10. StudentNumber varchar(12) NOT NULL,
  11. StudentFirstName varchar(15) NOT NULL,
  12. Course_id int NOT NULL,
  13. FOREIGN KEY (Course_id) REFERENCES CourseList(Course_id) ON DELETE CASCADE
  14. )';

how should i write foreign key code to link "StudentAccess's Course_id" to "CourseList's Course_id"??
Last edited by peter_budo; Jan 6th, 2009 at 2:01 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SOB224 is offline Offline
4 posts
since Jan 2009
Jan 3rd, 2009
0

Re: Foreign Key is different than primary key

I notice on the Foreign key explanation from the MySQL manual that their tables are INNODB.

http://dev.mysql.com/doc/refman/5.1/...nstraints.html
Reputation Points: 10
Solved Threads: 4
Light Poster
DiGSGRL is offline Offline
45 posts
since May 2008
Jan 3rd, 2009
0

Re: Foreign Key is different than primary key

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
SOB224 is offline Offline
4 posts
since Jan 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: difference between IE and Firefox
Next Thread in PHP Forum Timeline: How to assign Menu lists' values to variables?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC