How to delete a row with data with its parent row in another table

后端 未结 3 1839
醉酒成梦
醉酒成梦 2020-12-12 00:21

There are two tables [UserData] and [HotelData] I\'ve linked them with a foreign key. which is \"Username\" and I want to delete which

3条回答
  •  醉话见心
    2020-12-12 00:52

    There is no need to write any code to delete data on the child table when you delete a record from the UserData table. Just use Cascade delete behavior. It means that if a record in the parent table is deleted, then the corresponding records in the child table will automatically be deleted.

    Do the following steps:

    1. Open the child table's designer and click Relationships
    2. In the opened window and in the Table Designer expand INSERT And UPDATE Specification
    3. Change the Delete Rule from No action to Cascade

    Like the following image:

提交回复
热议问题