MySQL InnoDB

Hi,

I am trying to use on delete cascade and do this I believe I need InnoDB, is this true?

Also do I have to install InnoDB manually or does it come with MySQL and automatically works?

James.

Yes, you will have to use InnoDB. It has support to constraints.

It comes with MySQL.

Thanks.




create table a(


	id int auto_increment primary key,

	name varchar(50)


);


create table b(


	id int auto_increment primary key,

	fk_id int not null,

	foreign key (fk_id) references a (id) on delete cascade


);



Hi, I have this, when I delete a record, shouldnt it delete the corresponding record as well?

You have to set the engine to InnoDB.




create table a(

        id int auto_increment primary key,

        name varchar(50)

) engine = InnoDB;


create table b(

        id int auto_increment primary key,

        fk_id int not null,

        foreign key (fk_id) references a (id) on delete cascade

) engine = InnoDB;



See http://dev.mysql.com/doc/refman/5.1/en/create-table.html.

Use mysql workbench or a similar tool to design your relational database.

Without such a tool, you will screw it up big time when you have, let’s say, > 50 tables.

Very good advice on using MySQL Workbench. Download it here.