Liquibase cascade DELETE many to many基于WHERE子句



是否可以级联删除与Liquibase xml?

例如,假设我有以下表,我想从Drivers中删除一行。我还想删除CarDrivers中的所有相关行。

Table Cars:
CarID      int
CarName    nvarchar(100)
Table Drivers:
DriverID   int
DriverName nvarchar(100)
Table CarDrivers:
CarID      int
DriverID   int

执行此操作的SQL看起来像这样:

DELETE
FROM CarDrivers cd
WHERE cd.DriverID IN (
SELECT ID 
FROM Drivers d 
WHERE d.DriverName IN ("John", "Smith")
);
DELETE
FROM Drivers
WHERE DriverName IN ("John", "Smith");

您可以使用变化类型。您可以在此页面找到更多详细信息:https://docs.liquibase.com/change-types/community/sql.html

相关内容

  • 没有找到相关文章

最新更新