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

后端 未结 3 1837
醉酒成梦
醉酒成梦 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 00:57

    Well. To expand on the other option which isn't exactly ideal, but should be available as well. CASCADE is easier to work with though.

    Without that, your best bet is

    DELETE FROM HotelData WHERE Username = @Username
    

    Followed by

    DELETE FROM UserData WHERE Username = @Username
    

提交回复
热议问题