Hướng dẫn học Microsoft SQL Server 2008 part 15 potx

10 353 0
Hướng dẫn học Microsoft SQL Server 2008 part 15 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 102 Part I Laying the Foundation on a workstation, and connects to the actual server. Management Studio sends T-SQL commands to SQL Server, or uses SQL Management Objects (SMOs), just like any other client application. It also inspects SQL Server and presents the data and configuration for viewing. It’s interesting to watch the commands sent by Management Studio to SQL Server. While Management Studio can generate a script for nearly every action, the actual traffic between SQL Server and its clients may be viewed using SQL Profiler, which is discussed in Chapter 56, ‘‘Tracing and Profiling.’’ What’s New in Management Studio? S QL Server 2008’s Management Studio is an evolution of SQL Server 2005’s Management Studio, which was a merger of the old Enterprise Manager and Query Analyzer. Besides a few new nodes in Object Explorer and small tweaks to the UI, Management Studio has two new very cool powerful features worth mentioning: ■ Using Registered Servers and Server Groups, the Query Editor can now send T-SQL statements to multiple servers with a single execute. ■ The Query Editor now includes a very nice IntelliSense that completes table and column names, and a code outlining feature that collapses multi-line statements and procedures. For SQL Server 2008, Buck Woody (SSMS 2008 Product Manager) and his team went all out with enhancements, tweaks, and new features. The new supercharged Management Studio is one of my personal favorite new features of SQL Server 2008, with at least 28 (count ‘em) features: ■ Using Registered Servers and Server Groups, the Query Editor can now send T-SQL statements to multiple servers with a single execute. ■ Registered servers can now point to a configuration server, a central server that holds the configuration settings for several instances of SSMS so DBAs can share server configurations. ■ Partitioning is easier to configure using a new wizard. ■ Performance Studio presents drill-through reports of information gathered by the Performance Data Warehouse. ■ The Activity Monitor can be launched for the SPID currently being viewed. ■ Table Designer and Database Designer have new safety features to prevent accidental data loss. ■ Setting security permissions has been redesigned for fewer required clicks and better display of a principal’s effective permissions. ■ Many SSMSs offer an Info-bar that provides user guidance. ■ Info-bar color can be set on a per-server basis. For example, the development server could be green while the production server is red. continued 102 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 103 Using Management Studio 6 continued ■ A new Activity Monitor designed for the DBA provides better information, including active sessions, wait states, file I/O, and long-running queries. Object Explorer has several enhancements: ■ A new Object Explorer Details page displays a ton of information about the object, including configuration columns and a Vista-like properties panel at the bottom of the page. ■ Object Search makes it easier to locate the right object. ■ Data can be copied from the Object Explorer Details grid as tab-delimited data with headers. ■ The number of rows returned by selecting Object Explorer ➪ Select Top n Rows and Object Explorer ➪ Edit Top n Rows can be set in Options. ■ PowerShell can be launched from most nodes in Object Explorer. ■ Service Broker can now be configured and controlled from Object Explorer. The Query Editor alone has several enhancements: ■ IntelliSense completes table and column names. ■ IntelliSense tooltips provide detailed information about objects and parameters. ■ Code outlining features collapse multi-line statements and procedures. ■ Customizable tabs ■ Launch profiler from the Query Editor ■ The Error List recalls the last T-SQL errors. ■ The T-SQL debugger is back! ■ The results grid context menu is now capable of copying, copying with headers, and saving the results to CSV or tab-delimited files. Working with query execution plans, also called showplans, is improved with new options: ■ An XML query plan (from sys.dm_exec_query_plan) can be opened as a graphical query plan. ■ XML showplans are now formatted for easier viewing. ■ Graphic execution plans can be converted to XML showplans. ■ Saved graphic execution plans can be converted back into the original query. In addition, the framework on which SSMS is based received an overhaul focused on improving load time and overall performance. In addition, one of Ken Henderson’s final tasks with Microsoft before his untimely passing was performance-tuning the queries that SSMS sends to SQL Server. (Ken was the author of the famous SQL Server Guru series of books, a popular conference speaker, a friend of the SQL community, and a brilliant SQL programmer. He is missed by the SQL community.) 103 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 104 Part I Laying the Foundation Organizing the Interface Management Studio includes a wide variety of functionality organized into 13 tools, which may be opened from either the View menu, the standard toolbar, or the associated hotkey: ■ Object Explorer (F8): Used for administering and developing SQL Server database objects. The Object Explorer Details page presents a list of objects under the selected node. In SQL Server 2005 Management Studio, F8 opened Object Explorer. That was removed in SQL Server 2008. To get that functionality back, revert to SQL Server 2000 keyboard lay- out (Tool ➪ Options ➪ Environment ➪ Keyboard). Object Explorer will now open with F8, even after resetting the keyboard layout to Standard. ■ Registered Servers (Ctrl+Alt+G): Used to manage the connections to multiple SQL Server 2005 engines. You can register database engines, Analysis Services, Report Servers, SQL Server Mobile, and Integration Services servers. ■ Template Explorer (Ctrl+Alt+T): Used to create and manage T-SQL code templates ■ Solution Explorer (Ctrl+Alt+L): Organizes projects and manages source code control ■ Properties window (F4): Displays properties for the selected object ■ Bookmarks window (Ctrl+K, Ctrl+W): Lists current bookmarks from within the Query Editor ■ Web Browser (Ctrl+Alt+R): Used by the Query Editor to display XML or HTML results ■ Output window (Ctrl+Alt+O): Displays messages from Management Studio’s integrated development tools. ■ Query Editor: The descendant of SQL Server 2000’s Query Analyzer, the Query Editor is used to create, edit, and execute T-SQL batches. Query Editor may be opened from the File ➪ New menu by opening an existing query file (assuming you have the .sql file extension associated with Management Studio); by clicking the New Query toolbar button; or by launching a query script from an object in Object Explorer. ■ Toolbox (Ctrl+Alt+X): Used to hold tools for some tasks ■ Error List (Ctrl+\,Ctrl+E): Lists multiple errors ■ Task List (Ctrl+Alt+K): Tracks tasks for solutions The most commonly used tools — Query Editor, Object Explorer, Template Explorer, and Properties windows — are available on the standard toolbar. This chapter primarily discusses Management Studio because it is used with the Relational Engine, but Management Studio is used with the Business Intelligence (BI) tools as well. Part 10 covers the BI tools. Window placement Using the Visual Studio look and feel, most windows may float, be docked, be part of a tabbed window, or be hidden off to one side. The exception is the Query Editor, which shares the center window — the document window. Here, multiple documents are presented, with tabs enabling selection of a document. 104 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 105 Using Management Studio 6 Any window’s mode may be changed by right-clicking on the window’s title bar, selecting the down arrow on the right side of a docked window, or from the Window menu. In addition, grabbing a window and moving it to the desired location also changes the window’s mode. Following are the available options by either dragging the tool’s window or using the tool’s context menu: ■ Setting the mode to floating instantly removes the window from Management Studio’s window. A floating window behaves like a non-modal dialog box. ■ Setting the mode to tabbed immediately moves the window to a tabbed document location in the center of Management Studio, adding it as a tab to any existing documents already there. In effect, this makes the tool appear to become a tab in the Query Editor. Dragging a tab to a side location creates a new tabbed document. Any location (center, right, left, top, bottom) can hold several tabbed tools or documents. The center document location displays the tabs on the top of the documents, the other locations display the tabs at the bottom. A tabbed document area can hold more documents than the space allows to display the tabs. There are two ways to view the hidden tabs. Ctrl+Tab opens the active tool’s window and scrolls through the open files, or the Active File arrow in the upper right-hand corner of the tabbed document area opens a drop-down list of the tabs. ■ While a dockable window is being moved, Management Studio displays several blue docking indicators (see Figure 6-1). Dropping a window on the arrow will dock it in the selected location. Dropping the window on the center blue spot adds the window to the center location as a tabbed document. The free screencast Using SQL Server Management Studio , demonstrates the various ways to move, dock, and hide Management Studio’s windows. See www.SQLServerBible.com. ■ Opening several windows will keep the tools right at hand, but unless you have a mega monitor (a 24  widescreen works well!), the windows will likely use too much real estate. One solution is auto-hiding any docked window that you want out of the way until the window’s tab is clicked. To auto-hide a window, use the View ➪ Auto-Hide menu command or toggle the pin icon in the window’s title bar. When the pin is vertical, the window stays open. When the window is unpinned, the window auto-hides. An auto-hidden window must be pinned back to normal before its mode can be changed to floating or tabbed. Unfortunately, I find that I accidentally open the hidden tab so much that I avoid auto-hiding windows, but you might be more coordinated and find the feature useful. Ctrl+Tab displays all windows and documents. You can click on a window or document with the Ctrl key still pressed to select it. You can also use the arrow keys with the Ctrl key still pressed and release Ctrl when the window you need is selected. One press of Ctrl+Tab will select the most recently selected document. Repeatedly pressing Ctrl+Tab will cycle though all the documents in the center location. I use Ctrl+Tab regularly. To reset Management Studio to its default configuration (Object Explorer ➪ Tabbed Documents ➪ Property Window) use the Window ➪ Reset Window Layout menu command. Fortunately, this command does not reset any custom toolbar modifications. To hide all the docked windows and keep only the tabbed documents in the center visible, use the Win- dow ➪ Auto Hide All menu command. 105 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 106 Part I Laying the Foundation This flexible positioning of the windows means you can configure the interface to give you access to the tools in whatever way makes you the most comfortable and productive. Personally, I tend to close every window but the Query Editor and work with multiple scripts using the vertical split panes, as shown in Figure 6-2. FIGURE 6-1 Moving a floating window in Management Studio presents several drop points. The shaded area indicates where the dropped window will be placed. The Context Menu In keeping with the Microsoft Windows interface standards, the context menu (accessed via right-click) is the primary means of selecting actions or viewing properties throughout Management Studio. The context menu for most object types includes submenus for new objects, and tasks. These are the workhorse menus within Management Studio. Add /nosplash to your SQL Server Management Studio shortcut(s) to improve startup time. 106 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 107 Using Management Studio 6 FIGURE 6-2 Although Management Studio can be configured with multiple windows, this is my most common configuration for doing development work: Object Explorer Details for searches and Query Editor for script-style coding in the tabbed view, with a little Object Explorer on the side. Registered Servers Registered Servers is an optional feature. If you manage only one or a few SQL Servers, then Registered Servers offers little benefit. If, however, you are responsible for many SQL Servers, then this is the right place to take control. Using Registered Servers, connection information can be maintained for connections to the Database Engine, Analysis Services, Reporting Services, SQL Server Mobile Edition Databases, and Integration Services. The toolbar at the top of Registered Servers enables selection among the types of services. Managing Servers Servers are easily registered using the context menu and supplying the Properties page with the server name, authentication, and maybe the connection information. One key benefit of registering a server is 107 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 108 Part I Laying the Foundation that it can be given an alias, or Registered Server Name, in the Properties page, which is great if you’re a DBA managing dozens of servers with the serial number as the server name. Once a server is registered, you can easily select it, and using the context menu, connect to it with Object Explorer or the Query Editor. While this is a good thing, the server aliases don’t propagate to Object Explorer, which can lead to confusion. The workaround is to keep Object Explorer free from all other connections except those currently in use. The Server context menu, shown in Figure 6-3, can also be used to connect to the server with Object Explorer or the Query Editor, or to apply Policies. Other tasks include starting and stopping the service, and opening the server’s Registration Properties page. To share your registered server list, or move from one SSMS installation to another, import and export the server configurations by selecting the context menu ➪ Tasks ➪ Import/Export, respectively. FIGURE 6-3 Registered Servers is the tool used to manage multiple servers. Here, a new query was opened from the Local Server Groups node in Registered Servers. The new query is connected to both the Maui and Maui/Copenhagen servers. The Query Editor Results pane adds the Server Name column as it combines the results from both servers. 108 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 109 Using Management Studio 6 Server Groups Within the Registered Servers tree, servers may be organized by server groups. This not only organizes the servers, but enables new group actions as well. ■ Local Server Groups: Stores the connection information in the local file system. Think of these as Management Studio groups. ■ Configuration Server Groups: New in SQL Server 2008, these store the connection infor- mation in a specified server. Groups are then created under the configuration server, so the tree in Registered Servers flows from Database Engine to Configuration Servers to the server selected as the configuration server, to a configuration group, to all the servers in the configuration group, as shown in Figure 6-3. The server group (local or configuration servers) context menu includes the same Object Explorer, Query Editor, and Policy commands as registered servers, but when these commands are executed from the group, they apply to all servers in the group or group. ■ Object Explorer: Opens Object Explorer and connects every server in the server group. ■ Query Editor: Opens with a connection to the group instead of a connection to the server. T-SQL commands are then submitted to every server simultaneously. The Query Editor merges (unions) the results from every server and adds two columns, server name and login, to indicate which server returned each row. The columns, and whether results are merged or returned in separate result sets, can be configured in Tools ➪ Options – Query Results ➪ SQL Server ➪ MultiServer Results, or Query Editor ➪ Query Options ➪ Results ➪ MultiServer. Messages will now include the server name and login. ■ Declarative Management Framework Policies may be applied to every server in the group. SSMS: Registered Server Groups and MultiServer Queries is an online screencast that demonstrates setting up server groups and sending T-SQL to multiple servers. See www.SQLServerBible.com. The Great Graphical vs. Scripts Debate S orry for the hype — there isn’t really any debate because the SQL Server development team’s goal for Management Studio is to enable you to perform any task using your choice of graphical or script. In addition, you should be able to script any graphical action to a script. This is part of what I was referring to in Chapter 1 when I said that I like SQL Server because the experience is scalable. You choose how you want to work with SQL Server. Personally, I write scripts by hand, but it’s a common practice to prepare changes in the graphical tool, and then script them but not actually execute them. There are several advantages to working with scripts. Scripts (especially alter scripts) can be developed on the dev server, checked into SourceSafe, deployed to test, and then production. I think of DDL as source code. Scripts can be checked into source control. Graphical clicks cannot. 109 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 110 Part I Laying the Foundation Management Studio is not the only way to submit T-SQL scripts to SQL Server. For details on running the command-line interface, SQLCmd, refer to Chapter 42, ‘‘Maintaining the Database.’’ Object Explorer Object Explorer offers a well-organized view of the world of SQL Server. The top level of the tree lists the connected servers. Object Explorer can connect to a server regardless of whether the server is known by Registered Servers. The server icon color indicates whether or not the server is running. Navigating the tree In keeping with the Explorer metaphor, Object Explorer (see Figure 6-4) is a hierarchical, expandable view of the objects available within the connected servers. Each Database Engine server node includes Databases, Security, Server Objects, Replication, Manage- ment, and SQL Server Agent. Most of the tree structure is fixed, but additional nodes are added as objects are created within the server. The Databases node contains all the server’s databases. When you right-click on a database, the con- text menu includes a host of options and commands. Under each database are standard nodes (refer to Figure 6-4), which manage the following database objects: ■ Database Diagrams: Illustrates several tables and their relationships. A database may contain multiple diagrams, and each diagram does not need to display all the tables. This makes it easy to organize large databases into modular diagrams. ■ Tables: Used to create and modify the design of tables, view and edit the contents of tables, and work with the tables’ indexes, permissions, and publications. Triggers, stored procedures that respond to data-modification operations (insert, update, and delete), may be created and edited here. The only way to launch the Query Designer is from the table listing. ■ Views: Stored SQL statements are listed, created, and edited, and the results viewed, from this node. ■ Synonyms: These are alternative names for SQL Server database objects. ■ Programmability: A large section that includes most of the development objects, stored procedures, functions, database triggers, assemblies, types, rules, and defaults ■ Service Broker: Used to view Server Broker objects, such as queues and contracts ■ Storage: Used to manage non-standard storage such as full-text search, and table partitions ■ Security: Used to manage security at the database level 110 www.getcoolebook.com Nielsen c06.tex V4 - 07/21/2009 12:23pm Page 111 Using Management Studio 6 FIGURE 6-4 Object Explorer’s tree structure invites you to explore the various components of SQL Server management and development. 111 www.getcoolebook.com . new features of SQL Server 2008, with at least 28 (count ‘em) features: ■ Using Registered Servers and Server Groups, the Query Editor can now send T -SQL statements to multiple servers with a. side. Registered Servers Registered Servers is an optional feature. If you manage only one or a few SQL Servers, then Registered Servers offers little benefit. If, however, you are responsible for many SQL Servers,. Configuration Server Groups: New in SQL Server 2008, these store the connection infor- mation in a specified server. Groups are then created under the configuration server, so the tree in Registered Servers

Ngày đăng: 04/07/2014, 09:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan