Primary Foreign key relationship in mysql.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
nadeem14375
Forum Newbie
Posts: 23
Joined: Sat Oct 30, 2010 2:11 am

Primary Foreign key relationship in mysql.

Post by nadeem14375 »

Dear members,

I have the following tables with constraints:

create table test(
student_no numeric,
student_name varchar(50),
ad_date date);

alter table test
add constraint testpk primary key (student_no);

create table test2(
student_no numeric,
student_name varchar(50),
ad_date date);

ALTER TABLE test2
ADD CONSTRAINT FOREIGN KEY
(student_no)
REFERENCES test (student_no);
---------------------------------
but at the time of insertion in table test2 it don't validate from the parent table.
I am using mysql Server version: 5.1.41.

please guide me whats the problem.

Regards:
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Primary Foreign key relationship in mysql.

Post by Celauran »

Which engine are you using? MyISAM does not support foreign keys.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Primary Foreign key relationship in mysql.

Post by califdon »

It isn't clear what you are trying to accomplish. It doesn't make any sense to have 2 tables related in that manner. If you are trying to learn about relational tables, you will find it far more valuable to work with reasonable examples.
Post Reply