Foreign Key is different than primary key

Reply

Join Date: Jan 2009
Posts: 4
Reputation: SOB224 is an unknown quantity at this point 
Solved Threads: 0
SOB224 SOB224 is offline Offline
Newbie Poster

Foreign Key is different than primary key

 
0
  #1
Jan 3rd, 2009
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:

  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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 45
Reputation: DiGSGRL is an unknown quantity at this point 
Solved Threads: 4
DiGSGRL's Avatar
DiGSGRL DiGSGRL is offline Offline
Light Poster

Re: Foreign Key is different than primary key

 
0
  #2
Jan 3rd, 2009
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
A little clarification goes a long way.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 4
Reputation: SOB224 is an unknown quantity at this point 
Solved Threads: 0
SOB224 SOB224 is offline Offline
Newbie Poster

Re: Foreign Key is different than primary key

 
0
  #3
Jan 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC