test sql deleting

I have the following query

DELETE o
FROM Orders o LEFT OUTER JOIN  OrderItems On o.Id = OrderItems.OrderId
Where OrderItems.OrderId IS NULL and o.OrderStatus > 1  

is there a way i can test this script but not let it actually run so i can see the results

I can of course use a select but i'm not sure the results are the same.

select *
FROM Orders o LEFT OUTER JOIN  OrderItems On o.Id = OrderItems.OrderId
Where OrderItems.OrderId IS NULL and o.OrderStatus > 1  
frosty1Asked:
Who is Participating?
 
Ryan McCauleyConnect With a Mentor Data and Analytics ManagerCommented:
Given the SQL query you provided:

DELETE o
FROM Orders o LEFT OUTER JOIN  OrderItems On o.Id = OrderItems.OrderId 
Where OrderItems.OrderId IS NULL and o.OrderStatus > 1

Open in new window


The changing the "DELETE o" to "SELECT o.*" will provide EXACTLY the same results - it will show all the rows that would be deleted:

SELECT o.*
FROM Orders o LEFT OUTER JOIN  OrderItems On o.Id = OrderItems.OrderId 
Where OrderItems.OrderId IS NULL and o.OrderStatus > 1

Open in new window


There's no way to directly preview what would be done by your DML - a kind of "run this query but not really, just show me the results" doesn't exist. The closest you can get is a "BEGIN TRANSACTION", then execute your SQL query to delete the rows, view the results, and then do a ROLLBACK. Obviously not ideal - use the SELECT query I've provided to preview your results.
0
 
cheers4beersCommented:
What database platform are you using? SQL Server or Oracle?
0
 
frosty1Author Commented:
mssql
0
 
SharathData EngineerCommented:
>> I can of course use a select but i'm not sure the results are the same.

With SELECT statement, you will get those records which can be deleted with DELETE statement.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.