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

后端 未结 3 1836
醉酒成梦
醉酒成梦 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:57

    The DELETE statement conflicted with the REFERENCE constraint "FKHotelData"

    You have a constraint and this is helping with performance, do yourself a favor and add a column IsDeleted with a default value of 0 or to allow null's so it doesn't affect anything.

    Then change your SELECT queries to have a WHERE clause that includes the condition

    WHERE IsDeleted = 0

    The point here is that its a Hotel business and they will want metrics/reporting on bookings. For medical and confidentiality purposes I'd lean toward the cascading delete answers. For this scenario it would be better to logically delete the data instead of physically delete it.

提交回复
热议问题