Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

100


Part I: Laying the Foundations


You can set Query Editor’s connection bar’s (at the bottom of the Query Editor) display color per connected server.
This is a great visual cue. You can set the development server to green and the production server to red. When con-
necting to a server, open the connection dialog’s options, and select Use Custom Color to set the color for that
server.

Opening a .sql File
You can open a saved query batch fi le in multiple ways, and a huge trap you want to avoid
follows:

■ (^) If Management Studio is not open, double-clicking a .sql fi le in Windows File Explorer
launches Management Studio, prompts you for a connection, and opens the fi le. Here’s
the gotcha: If you select multiple .sql fi les in Windows File Explorer and open them
as a group, Windows launches a separate instance of Management Studio for each
fi le — not a good thing. You end up running several copies of Management Studio.
■ If Management Studio is already open, double-clicking opens the fi le or selected
fi les into a Query Editor document. Each fi le prompts you for a connection.
■ Multiple .sql fi les may be dragged from Widows File Explorer and dropped
on Management Studio. Each fi le opens a Query Editor after prompting for a
connection.
■ (^) The most recently viewed fi les are listed in the Files ➪ Recent Files menu. Selecting
a fi le opens it in the Query Editor.
■ (^) The File ➪ File Open menu or toolbar command opens a dialog box to select one or
more fi les.
Real-World Developing with the Query Editor
With the release of SQL Server 2012, SQL Server Data Tools should be the preferred development
environment for all developers. If you wish to stick to developing within Management Studio, here are
some tips for using the Query Editor as a developer.
■ (^) View multiple scripts at the same time in Quer y Editor by right- clicking one of the documents
and selecting New Vertical Tab Group. The selected document is the one that becomes
the new tab to the right.
■ (^) Liberally use bookmarks to save points in the script to which you’ll need to refer back. For
example, I’ll bookmark a table’s DDL code, and the CRUD stored procedures for that table,
while I’m working on the stored procedures.
■ (^) Begin every script with usedatabase and set nocount on. (Chapter 16, “Programming
with T-SQL,” covers these commands.) Every script ends with use tempdb. That way if you
run all the scripts, no script stays in the user database, and the initial create script can easily
drop and re-create the database.
c05 July 23, 2012 11:44 AM V1
c05.indd 100c05.indd 100 7/30/2012 4:14:50 PM7/30/2012 4:14:50 PM
http://www.it-ebooks.info

Free download pdf