| | |
Foreign Key is different than primary key
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2009
Posts: 4
Reputation:
Solved Threads: 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:
how should i write foreign key code to link "StudentAccess's Course_id" to "CourseList's Course_id"??
currently foreign key has all zero values in all of the rows.
Table codes:
php Syntax (Toggle Plain Text)
$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"??
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.
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
http://dev.mysql.com/doc/refman/5.1/...nstraints.html
A little clarification goes a long way.
![]() |
Similar Threads
- Foreign and primary key (MS SQL)
- Help with composite and Foreign Keys (Database Design)
- Total noob question (Database Design)
- Foreign Keys (MySQL)
- change primary key (MS SQL)
- Assigning Foreign Keys (Database Design)
- Primary Key Issue (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: cannot connect to mysql server
- Next Thread: How to assign Menu lists' values to variables?
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary bounce broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail malfunctioning menu mlm mod_rewrite multiple mysql nodes oop parse paypal pdf php problem query radio ram random recursion reference regex remote return script search server sessions show sms soap source space sql structure syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube






