In T-SQL the connection is handled entirely by the Query window you open. Unless you specify a database name in the Query then you can run the query against either test or production based on the query window.
In the case of TSQL it usually falls to the developer to manage the difference between TEST and PROD.
As a matter of Habit I add a Comment line to all of my scripts to specify what mode it is in.
--***************** IN TESTING ONLY********************
When I move the script to production I will change the comment line to In Production.
I also add comments for version control adding notes for when I change something and what I changed.
It is kind of an old method of version control but it works for me.
Dan
If only I could snap my figures and have all the correct indexes apear and the buffer clean and.... Start day dream here.