开发者

check if foreign key is used in other tables before delete data row hibernate

I have the following table structu开发者_JAVA技巧re:

table A 
---------
id | name

table B
--------------
id | x | y | z

table B (id) : references table A (id)

I can modify name of table A even if data present at table B for id of table A , as it is not a foreign key.

Now I want to restrict the modification of name variable of table A, if id of table A has records in other table. Do I need to query each table where id of table A is used as foreign key, or there is any other option in Hibernate or MySQL.


You can do that right in the database via a constraint on the key the foreign key refers to. The database will then take the action you specify automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜