database - MYSQL doesn't check for Foreign key exsistence -
i facing strange problem here.
table 1:
create table degree (degree_id varchar(6) primary key , degree_name varchar(32) unique key , degree_abbr varchar(3));
table 2:
create table course (course_id varchar(6) primary key , degree_id varchar(6) not null, course_name varchar(40) not null , foreign key (degree_id) references degree (degree_id));
now far understand sql , cannot insert value in course table if value of field degree_id doesn't exist in degree table.
but if try insert
insert course values('cor_001' , 'blah' , 'course name' );
this query runs , though 'blah' not valid degree_id.
you're using myisam tables, not support foreign keys. fk directives parsed , accepted, ignored.
you need use innodb tables proper fk support:
create table (...) engine=innodb; ^^^^^^^^^^^^^^
if show create table your_table
, you'll see engine type being used @ end of output.
Comments
Post a Comment