Rujikin
Rujikin

Reputation: 773

MySql on delete cascade concept?

I am trying to figure out how cascade delete works. I know the general concept but not the specifics of it.

I have 3 tables (a)||---|<(B)>o---||(C)

Table A:

Aid
Tag

Table B:

Aid (f)
Cid (F)

Table C:

Cid
Other

If I set Table B [Aid] to delete cascade would it:

  1. If the tag from table A is deleted automatically remove any links in table B
  2. I delete a row from table B belonging to tagz. There is another row in table B that references tagz. Would that deletion cause tagz to be deleted as well or would tagz remain so long as any row references it?

Upvotes: 1

Views: 4328

Answers (1)

Kris Fox
Kris Fox

Reputation: 431

If you have set up table B to delete cascade on the foreign key to table A then if a tag get's deleted the corresponding records in Table B will be deleted. Table B deletions will not affect table A since table A does not have any references or foreign keys into table B.

Upvotes: 5

Related Questions