MySql on delete cascade concept?

你离开我真会死。 提交于 2019-12-12 09:26:06

问题


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
  • A row in table A must have at least one reference to table c or else it should be deleted.
  • A row in table A is made only when Table C tries creating a tag that does not exist. If table C removes that tag and no other rows from table C reference that tag then the tag should be removed. If another row from table C references that tag then the tag should not be deleted.

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?

回答1:


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.



来源:https://stackoverflow.com/questions/14764493/mysql-on-delete-cascade-concept

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!