MySQL Forums
Forum List  »  InnoDB

Re: Foreign Keys Dont Work
Posted by: Radu Chiriac
Date: January 07, 2005 03:58PM

Oh, yes, they do! :)

btw, make up your mind - do u really want to set master.dept_id to null on parent record deletion or or want this field to be not null?

if you want it to be not null then:

create table master (
admission_id int not null,
adm_start_date datetime not null,
adm_end_date datetime,
admission_class varchar(20),
dept_id int not null,
ward_no int default 0,
primary key (admission_id),
constraint admission_dept foreign key (dept_id) references dept1(dept_id)
) ENGINE=InnoDB;

if u want it to be not null and on parent record deletion to delete automatically the record from the child table:

create table master (
admission_id int not null,
adm_start_date datetime not null,
adm_end_date datetime,
admission_class varchar(20),
dept_id int not null,
ward_no int default 0,
primary key (admission_id),
constraint admission_dept foreign key (dept_id) references dept1(dept_id) on delete cascade
) ENGINE=InnoDB;


And finally, if u want the field to accept null values and to be set to null on delete from parent table:
create table master (
admission_id int not null,
adm_start_date datetime not null,
adm_end_date datetime,
admission_class varchar(20),
dept_id int,
ward_no int default 0,
primary key (admission_id),
constraint admission_dept foreign key (dept_id) references dept1(dept_id) on delete set null
) ENGINE=InnoDB;


Have fun with mysql :)
Radu

Options: ReplyQuote


Subject
Views
Written By
Posted
4063
January 06, 2005 11:34PM
Re: Foreign Keys Dont Work
2512
January 07, 2005 03:58PM
2556
January 12, 2005 01:49AM
2436
January 09, 2005 07:15PM
2476
January 10, 2005 05:02PM
2418
January 12, 2005 05:37PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.