
- #Visual studio 2017 sql server execute only selected code how to
- #Visual studio 2017 sql server execute only selected code code
Tests Reviewįirst let’s review what PARSEONLY ON does. Why does this list of SQL Server clients matter? Well, due to GO being processed by the clients instead of SQL Server, there is the possibility of there being different behavior between the various clients. not ODBC) replacement for sqlcmd that I wrote: Simple SQL Exec. GO is also recognized by many 3rd party utilities, including an open source, lightweight ADO.NET-based (i.e.
#Visual studio 2017 sql server execute only selected code code
GO is not a Transact-SQL statement it is a command recognized by the sqlcmd and osql utilities and SQL Server Management Studio Code editor.Īpparently that list has not been updated to include: Visual Studio, Visual Studio Code, and Azure Data Studio. There are two things in particular that are of importance: syntax and where applicable. Let’s take a look at the documentation to see what the behavior is supposed to be: There are some statements that require being the only statement in a batch, such as CREATE PROCEDURE and CREATE VIEW, in which case GO will be used (assuming that you will be running the whole script in one execution and not merely highlighting each section to execute individually, in which case GO isn’t needed).

Some people put GO between most statements and that really isn’t necessary. Anyone who works with SQL Server and has submitted queries via client tools such as SQL Server Management Studio (SSMS), sqlcmd, and others has used GO to separate batches of query statements. What is this mysterious “technique”, you ask? Well, it’s none other than everyone’s favorite batch separator: GO. However, this “technique” is more limited than PARSEONLY as it only works on individual batches, and it only works in some environments.

I found a way to fully disable an entire T-SQL batch, and there really isn’t any indication that it happened.

Then one day I tried something silly that I figured wouldn’t work but wanted to try anyway (because quite often you don’t know until you know), and it actually did work (for the most part). This means that you could still see parsing errors related to undeclared variables, syntax errors, etc. It will still be parsed by SQL Server as that is not something that can be turned off. But in either case, “disabling” doesn’t mean that the script, or section of code, will be skipped entirely as if it wasn’t there. That same method can be used to disable one or more sections within a script instead of the entire script.
#Visual studio 2017 sql server execute only selected code how to
In a previous post, Prevent Full Script Execution (Understanding and Using PARSEONLY and NOEXEC), I explained how to easily disable a script using the PARSEONLY session setting.
