Microsoft® SQL Server® 2012 Bible

(Ben Green) #1

96


Part I: Laying the Foundations


■ (^) Previous versions of the Database Diagram tool were not schema aware, however,
the SQL Server 2012 version is and now displays the table schema in parentheses
after the table name.
■ There’s no way to select all the tables of a schema and add them to the diagram as
a set from the Object Explorer tree. The Object Explorer does not permit selecting
multiple tables. The Object Explorer Details page enables multiple table selection
but does not permit dragging the tables to the design. Even worse, the Add Table
dialog box in the Database Diagram tool does not sort by the table’s schema.
■ (^) The Add Related Tables option on the table’s context menu helps solve this problem.
■ Relationship lines have the frustrating tendency to become pretzels when tables or
lines are moved.
Best Practice
If your goal is to print the database diagram, be sure to check the page breaks and arrange the tables
fi rst, or you might end up wasting a lot of paper. To view the page breaks, use the tool’s context menu
or the Database Diagram menu.
The Query Designer
The Query Designer is a popular tool for data retrieval and modifi cation, even though it’s
not the easiest tool to fi nd within Management Studio. You can open it three ways:
■ Using the Object Explorer, select a table. Using the context menu, choose Edit Top
200 Rows. This opens the Query Designer, showing the return from a select top
(200) query in the results pane. You can now open the other panes using the Query
Designer menu or the toolbar.
■ When using the Query Editor, use the Query Designer button on the toolbar, use
the Query ➪ Design Query in Editor menu command, or use the Query Editor’s own
context menu.
■ (^) When you open the Query Designer from the Query Editor, it’s a modal dialog box,
and the results pane is disabled.
If editing 200 rows, or viewing 1,000 rows, seems like too many (or not enough) for your application, you can edit
those values in the Options ➪ SQL Server Object Explorer ➪ Command tab.
Unlike other query tools that alternate between a graphic view, a SQL text view, and the
query results, Management Studio’s Query Designer simultaneously displays multiple panes
(see Figure 5-8), as selected with the view buttons in the toolbar:
■ (^) Diagram pane: You can add multiple tables or views to the query and join them
together in this graphic representation of the SELECT statement’s FROM clause.
c05 July 23, 2012 11:44 AM V1
c05.indd 96c05.indd 96 7/30/2012 4:14:48 PM7/30/2012 4:14:48 PM
http://www.it-ebooks.info

Free download pdf