In order to change a connection for a single query in SQL Server Management Studio 2012 right click into the query text and select Connection > Change Connection ... from the context menu.

This will bring up a dialog in which you are able to change connection settings like the database server or the standard target database.

If you want to change details of the connection like selecting a database schema to connect to, expand the options in the bottom right of the connection dialog.

In the connection tab "Connection Properties" select the option "Connect to database" to show the target database you want and hit connect.