The other day I was trying to hit another button on the menu but hit Execute - which executed the whole code and ended up deleting some tables. I have always found this scary that hitting one button can execute the whole code.
I want SQL Server to execute code only when something is selected. Is it possible? Or can SQL Server prompt before executing a query?
If you wrap your code in NOEXEC then you effectively stop the code from running unless you select the code inside them.
The code will compile but will not execute!
Example:
SET NOEXEC ON;
SELECT 1 AS Test;
SET NOEXEC OFF;
If you run the whole code, nothing will be returned.
If you highlight just the SELECT part then it will run though, returning:
Test
----
1
In MSSQL Management Studio, the Execute button (F5) executes only the sentences that are selected. If nothing is selected, then executes the complete script.
I allways select the sentences I want to execute. But it's my habit. Nothing will prevent you from pressing F5 directly
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With