Primary Foreign key relationship in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
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:
maxx99
Forum Contributor
Posts: 142
Joined: Mon Nov 21, 2011 3:40 am

Re: Primary Foreign key relationship in mysql

Post by maxx99 »

What storage engine do you use for your db/tables?

You can check it by executing this query:

Code: Select all

SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Primary Foreign key relationship in mysql

Post by Benjamin »

:arrow: Duplicate = Locked
Locked