开发者

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

开发者 https://www.devze.com 2023-03-23 11:19 出处:网络
I have the following table structu开发者_JAVA技巧re: table A --------- id | name table B --------------

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

精彩评论

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