When you need to GO in your batch
Sometimes you'll run into a situation where you want to script a series of SQL batch statements dynamically. For instance, you might want to create a schema, then create a user to use that schema, then populate that schema with tables, and do that in each database that runs on a SQL instance.
If you weren't wanting to do this dynamically, you'd simply do something like this:
use [dbname];
go
Create schema [schema_name];
go
create user [username] for login [loginname] with default_schema=[schema_name];
go
That's not that big of a deal, really. But if we want to create a cursor to loop through all databases and run this SQL dynamically, we have a problem: we can't have the create schema statement in the same batch as the USE command, so we don't end up creating the schema in the correct database.