我尝试在表lif_books中的表lif_bookhascategory和lb_sku中删除具有相同lbhc_lb_sku的连接表。我无法删除它。
这是我的SQL命令:
DeleteCommand="DELETE FROM lif_books FROM lif_books CROSS JOIN lif_bookshascategory WHERE (lif_books.lb_sku = @lb_sku) AND (lif_bookhascategory.lbhc_lb_sku = @lb_sku)">
返回:
Incorrect syntax near the keyword 'INNER'.
答案 0 :(得分:2)
正式地说,SQL规范没有规定在动作查询中使用Join(插入,更新或删除)。在这种情况下,使用更通用的格式更简单:
Delete lif_books
Where lb_sku = @lb_sku
And Exists (
Select 1
From lif_bookhascategory
Where lbhc_lb_sku = @lb_sku
)
答案 1 :(得分:1)
我刚刚在我自己的数据库上测试了它,它确实有效。
DELETE lif_bookshascategory, lif_books
FROM lif_bookshascategory
INNER JOIN lif_books
WHERE lbhc_lb_sku = lb_sku
答案 2 :(得分:1)
这应该有效:
DELETE lif_bookshascategory, lif_books
FROM lif_bookshascategory
INNER JOIN lif_books
ON lif_bookshascategory.lbhc_lb_sku = lif_books.lb_sku