| | |
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 |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions simple sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube






