The problem of transaction blocking caused by database foreign key constraints

The

database has two tables for students and classes, and the field classId in the student table is associated with the field id in the class table.

clipboard.png
clipboard.png

in a transaction, I first changed the classId of student2 in the student table to 1, and then went to the class table to query the information of class2 according to id=2. At this time, blocking occurred, the query result could not be returned, and the whole transaction could not be executed. I think it should have something to do with foreign key constraints. do any bosses know the specific reasons?

Jul.04,2021
Menu