It’s April Fools’ Day which means you need to second guess everything you hear and if you’re back to working in an office LOCK YOUR COMPUTER BEFORE WALKING AWAY FROM YOUR DESK! If you fail to do so, you might fall victim to one of these SQL Server pranks.
I Keep Getting Disconnected
The first prank is one that will probably be discovered right away after it is set. Some may hesitate to call it a prank since it’s a setting built into SSMS (like others to come) but it will drive your coworker or soon to be ex-friend crazy if they’re not expecting it. If you go to Tools > Options > Query Execution > SQL Server > Advanced you will find an option for Disconnect after the query executes. If that box is checked, the connection will disconnect after any query is ran for each new query window.
The first disconnection will probably be brushed off as a fluke but after a few tries someone might be pulling their hair out.
Show Them Your Results
Prank number two is similar in that it’s another built in SSMS settings. Go to Tools > Options > Query Results > SQL Server > Results to Grid and find the check box for Discard results after execution. This assumes you’re using Results to Grid and you could make the same change in Results to Text. Now, each new query window will fail to show any results:
Again, this one will make itself apparent rather quickly. I’d suspect some smashing F5 and expecting different results besides a “rows affected” message. Or worse, someone running a SELECT statement, seeing the results above, and thinking to themselves for a split second “did I run an UPDATE or DELETE instead?”
This functionality can actually be useful. If you’re testing a query with a large result set, loading up that large result set could use a high percentage of memory and slow down SSMS. Having that option enabled can save you some time waiting around for queries to complete.
Go Means Go
Finally, our third and final prank is changing the batch separator. Under Tools > Options > Query Execution there is an option for Batch separator. Odds are it is currently set to GO. Typically, that means this type of statement would run fine:
What if we changed our batch separator from GO to AprilFools? If we open a new query window, GO no longer works and is not recognized:
But now if we replace GO with AprilFools our query runs without a problem:
Use common sense. Don’t pull any pranks that could possibly affect production data.
Thankfully, all of these settings can be easily reversed. Still, be smart about these pranks (or any pranks) and where you run them. As in, don’t mess with production.
Thanks for reading!