'How does one write a script to delete all Orders in the database without Orderline Items?

How does one write a script to delete all Orders in the database without Orderline Items?

Normally, you would delete all Orders like this:

delete from dbo_Orders

or

delete from dbo_Orders (where Id = 'orderid')

I also have a table dbo_OrderLines, which are linked in a One-to-Many relationship. I wish to delete all the orders which have no orderlines. How do I write the query?

delete from dbo_Orders (where this order's dbo_OrderLines count is 0)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source