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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cheers4beersCommented:
What database platform are you using? SQL Server or Oracle?
0
frosty1Author Commented:
mssql
0
Ryan McCauleyEnterprise 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.