use wroxdb
go
--
--   Name:  delete_order
--
--   Description: delete all records of an order
--
--
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'delete_order')
BEGIN
    DROP PROCEDURE delete_order
END
GO
 
PRINT 'delete_order'
GO
CREATE PROCEDURE delete_order @order int
AS
	SET NOCOUNT ON
	SET XACT_ABORT ON

	BEGIN TRAN
		DELETE payments WHERE order_no=@order

		DELETE lines WHERE order_no=@order
		
		DELETE orders WHERE order_no=@order
	COMMIT
GO
IF EXISTS (SELECT * FROM sysobjects WHERE name = 'delete_order')
   PRINT  '>>> Created procedure delete_order <<<'
GO

