M I C R O S O F T
L E A R N I N G
P R O D U C T
Information in this document, including URL and other Internet Web site references, is subject to change without notice. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. The names of manufacturers, products, or URLs are provided for informational purposes only and Microsoft makes no representations and warranties, either expressed, implied, or statutory, regarding these manufacturers or the use of the products with any Microsoft technologies. The inclusion of a manufacturer or product does not imply endorsement of Microsoft of the manufacturer or product. Links may be provided to third party sites. Such sites are not under the control of Microsoft and Microsoft is not responsible for the contents of any linked site or any link contained in a linked site, or any changes or updates to such sites. Microsoft is not responsible for webcasting or any other form of transmission received from any linked site. Microsoft is providing these links to you only as a convenience, and the inclusion of any link does not imply endorsement of Microsoft of the site or the products contained therein. 2011 Microsoft Corporation. All rights reserved. Microsoft, and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. All other trademarks are property of their respective owners.
Module 1
Introduction to SQL Server 2008 R2 and its Toolset
Contents:
Lesson 1: Introduction to the SQL Server Platform Lesson 2: Working with SQL Server Tools Lesson 3: Configuring SQL Server Services Module Reviews and Takeaways Lab Review Questions and Answers 8 11 17 21 22
Lesson 1
10
Additional Reading
SQL Server Architecture
SQL Server Home Page
11
Lesson 2
12
13
10. Note the use of Intellisense while entering it, and then click Execute on the toolbar. Note how the results can be returned. 11. From the File menu click Save SQLQuery1.sql. Note this saves the query to a file. 12. In the Results tab, right-click on the cell for ProductID 1 (first row and first cell) and click Save Results As. In the FileName textbox, type Demonstration2AResults and click Save. Note this saves the query results to a file. 13. From the Query menu, click Display Estimated Execution Plan. Note that SSMS is capable of more than simply executing queries. 14. From the Tools menu, and click Options. 15. In the Options pane, expand Query Results, expand SQL Server, and expand General. Review the available configuration options and click Cancel. 16. From the File menu, click Close. In the Microsoft SQL Server Management Studio window, click No. 17. In the File menu, click Open, and click Project/Solution. 18. In the Open Project window, open the project D:\6231B_Labs\6231B_02_PRJ\6231B_02_PRJ.ssmssln. 19. From the View menu, click Solution Explorer. Note the contents of Solution Explorer. SQL Server projects have been supplied for each module of the course and contain demonstration steps and suggested lab solutions, along with any required setup/shutdown code for the module. 20. In the Solution Explorer, click the X to close it.
14
21. In Object Explorer, from the Connect toolbar icon, note the other SQL Server components that connections can be made to: Database Engine, Analysis Services, Integration Services, Reporting Services, SQL Server Compact
22. From the File menu, click New, and click Database Engine Query to open a new connection. 23. In the Connect to Database Engine window, type (local) in the Server name text box. 24. In the Authentication drop-down list, select Windows Authentication, and click Connect. 25. In the Available Databases drop-down list, click tempdb database. Note this will change the database that the query is executed against. 26. Right-click in the query window and click Connection, and click Change Connection Note: this will reconnect the query to another instance of SQL Server. In the Connect to Server window, click Cancel. 27. From the View menu, click Registered Servers. 28. In the Registered Servers window, expand Database Engine, right-click Local Server Groups, and click New Server Group 29. In the New Server Group Properties window type Dev Servers in the Group name textbox and click OK. 30. Right-click Dev Servers and click New Server Registration 31. In the New Server Registration window, click Server name drop-down list, type (local) and click Save. 32. Right-click Dev Servers and click New Server Registration 33. In the New Server Registration window, click Server name drop-down list, type .\MKTG and click Save. 34. In the Registered Servers window, right-click the Dev Servers group and choose New Query. 35. Type the query as shown in the snippet below and click Execute toolbar icon.
SELECT @@version;
3. 4. 5. 6.
15
7. 8.
In the Connection Properties window, type (local) for the Server name and in the Connect to a database drop-down list, select AdventureWorks2008R2, and click OK. In the Select the Data Source window, click Next then in the Design the Query window, for the Query string textbox, type the following query as shown in snippet below and click Next.
9.
10. In the Design the Table window, click Details four times, and click Finish>>|. 11. In the Completing the Wizard window, click Finish. 12. In the Report1.rdl [Design] tab, click Preview and note the report that is rendered. 13. Click on the Design tab, from the File menu click Exit. Note do not save the changes.
10. Click the name of the function SUBSTRING, then hit the F1 key to open the BOL topic for SUBSTRING. 11. In the Online Help Settings window, ensure that theUse local Help as primary source option button is selected, and click OK. Note the content of the page and scroll to the bottom to see the examples then from the File menu, click Exit. 12. In the host system, open Internet Explorer and browse to the SQL Server Books Online page: http://msdn.microsoft.com/en-us/library/ms130214.aspx and note the available online options.
16
Additional Reading
Connecting from Clients and Applications
Connecting to the SQL Server Database Engine
Books Online
SQL Server Books Online Downloading and Updating Books Online
17
Lesson 3
18
19
10. In the Query window, type the query as shown in the snippet below, and click Execute toolbar icon.
USE AdventureWorks2008R2 GO SELECT * FROM Person.Person ORDER BY FirstName; GO
11. Switch to SQL Server Profiler. Note the statement trace occurring in SQL Server Profiler then from the File menu and click Stop Trace. 12. In the Results grid, click individual statements to see the detail shown in the lower pane.
20
Additional Reading
SQL Server Configuration Manager
SQL Server Configuration Manager
21
Best Practices
Ensure that developer edition licenses are not used in production environments. Develop using the least privileges possible, to avoid accidentally building applications that will not run for standard users. If using an offline version of Books Online, ensure it is kept up to date.
22
23
Module 2
Preparing Systems for SQL Server 2008 R2
Contents:
Lesson 1: Overview of SQL Server Architecture Lesson 2: Planning Server Resource Requirements Lesson 3: Pre-installation Testing for SQL Server Module Reviews and Takeaways Lab Review Questions and Answers 24 29 32 36 37
24
Lesson 1
25
Parallelism
Question: Why would parallel plans involve an overhead? Answer: Data is processed in different tasks and involves the need to gather the data together or repartition the data for further parallel operations. A good analogy is a human project. As soon as there are more people involved, management overhead occurs.
26
27
3. 4. 5.
28
Additional Reading
SQL Server Architecture
Platform layer for SQL Server An Overview of Query Optimization in Relational Systems Query Processing Architecture
Parallelism
Parallel Query Processing
29
Lesson 2
30
31
Additional Reading
Introduction to Planning Server Resource Requirements
SQL Server 2000 Operations Guide: Capacity and Storage Management
32
Lesson 3
33
Introducing SQLIO
Question: What types of I/O will SQL Server mainly produce against data files of a typical OLTP system? Answer: A big number of small random I/Os.
34
2. 3.
Open and execute the 00 Setup.sql script file from within Solution Explorer. Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
35
Additional Reading
Perform Pre-checks of I/O subsystems
Analyzing I/O Characteristics and Sizing Storage Systems for SQL Server Database Applications SQL Server Best Practice Article
Introducing SQLIOSIM
How to use the SQLIOSim utility to simulate SQL Server activity on a disk subsystem
Introducing SQLIO
SQLIO Disk Subsystem Benchmark Tool
36
Best Practices
Understand the architecture of SQL Server. Plan memory, CPU, network and I/O requirements for the specific system. Test these requirements against the available hardware.
37
38
Module 3
Installing and Configuring SQL Server 2008 R2
Contents:
Lesson 1: Preparing to Install SQL Server Lesson 2: Installing SQL Server Lesson 3: Upgrading and Automating Installation Module Reviews and Takeaways Lab Review Questions and Answers 39 43 47 50 51
39
Lesson 1
40
41
3. 4. 5.
42
Additional Reading
Hardware Requirements - General
Hardware and Software Requirements for Installing SQL Server 2008 R2
43
Lesson 2
44
45
10. In the Setup Support Rules window, note the list of rules which have been checked. 11. Click on the warning in the Status column for the Microsoft .NET Application Security rule. 12. In the Rule Check Result window, read the details of the warning and click OK. 13. In the Setup Support Rules window, click OK.
46
Additional Reading
Overview of the Installation Process
Installing SQL Server 2008 R2
Post-installation Checks
Validating a SQL Server Installation How to: View and Read SQL Server Setup Log Files
47
Lesson 3
48
2. 3.
Open the 31 ConfigurationFile.ini file. Review the Configuration File, in particular note the values of the following properties: INSTANCEID ACTION FEATURES QUIET QUIETSIMPLE INSTALLSHAREDDIR INSTANCEDIR INSTANCENAME AGTSVCSTARTUPTYPE SQLCOLLATION SQLSVCACCOUNT SQLSYSADMINACCOUNTS TCPENABLED
49
Additional Reading
Upgrading SQL Server
Considerations for Side-by-Side Instances of SQL Server 2008 R2 and SQL Server 2008 Working with Multiple Versions and Instances of SQL Server
Unattended Installation
How to: Install SQL Server 2008 R2 from the Command Prompt
50
Best Practices
Use domain-based accounts for service accounts. Configure service accounts for the least possible privilege that lets them still operate. Use SQL Server Configuration Manager to change service accounts as it will ensure that the correct permissions and ACLs are configured.
51
52
Module 4
Working with Databases
Contents:
Lesson 1: Overview of SQL Server Databases Lesson 2: Working with Files and Filegroups Lesson 3: Moving Database Files Module Reviews and Takeaways Lab Review Questions and Answers 53 57 61 65 66
53
Lesson 1
54
Overview of tempdb
Question: Why could a memory bottleneck lead to higher tempdb usage? Answer: Because SQL Server might need to page operations like hash or sort operations to tempdb, when it is low on memory.
55
3. 4. 5.
56
Additional Reading
How Data is Stored in SQL Server
Files and Filegroups Architecture Understanding Pages and Extents Transaction Log Physical Architecture
Overview of tempdb
Working with tempdb in SQL Server 2005 Capacity Planning for tempdb
57
Lesson 2
58
59
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
2. 3.
Open the 22 Demonstration 2B.sql script file. Follow the instructions contained within the comments of the script file.
2.
60
Additional Reading
Creating User Databases
CREATE DATABASE (Transact-SQL)
Altering Databases
ALTER DATABASE File and Filegroup Options (Transact-SQL)
61
Lesson 3
62
Copying Databases
Question: What might be the main disadvantage copying a database using detach and attach of the database? Answer: The database needs to be offline.
63
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
Open the 32 Demonstration 3B.sql script file. Follow the instructions contained within the comments of the script file.
64
Additional Reading
Overview of Detach and Attach
Detaching and Attaching Databases
Copying Databases
Using the Copy Database Wizard
65
Best Practices
Plan and test your file layout carefully. Separate data and log files on the physical level. Keep the data files of a database at the same size. Create the database in an appropriate size that it doesnt has to be expanded too often. Shrink files only if absolutely necessary.
66
67
Module 5
Understanding SQL Server 2008 R2 Recovery Models
Contents:
Lesson 1: Backup Strategies Lesson 2: Understanding SQL Server Transaction Logging Lesson 3: Planning a SQL Server Backup Strategy Module Reviews and Takeaways Lab Review Questions and Answers 68 71 75 78 79
68
Lesson 1
Backup Strategies
Contents:
Question and Answers Additional Reading 69 70
69
70
Additional Reading
Determining an Appropriate Backup Strategy
Backup Overview
71
Lesson 2
72
73
3. 4. 5.
74
Additional Reading
Overview of SQL Server Transaction Logs
Transaction Log Architecture
75
Lesson 3
76
77
Additional Reading
Overview of Microsoft SQL Server Backup Types
Backup Overview (SQL Server)
78
Best Practices
Plan your backup strategy carefully. Plan the backup strategy in conjunction with the business needs. Choose the appropriate database recovery model. Plan your transaction log size based on the transaction log backup frequency. Consider differential backups to speed up recovery.
79
80
Module 6
Backup of SQL Server 2008 R2 Databases
Contents:
Lesson 1: Backing up Databases and Transaction Logs Lesson 2: Managing Database Backups Lesson 3: Working with Backup Options Module Review and Takeaways Lab Review Questions and Answers 81 85 89 93 94
81
Lesson 1
82
83
3. 4. 5.
84
Additional Reading
Performing a Full Database Backup
Full Database Backups
85
Lesson 2
86
87
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
88
Additional Reading
Options for Ensuring Backup Integrity
Using Mirrored Backup Media Sets Verifying Backups
89
Lesson 3
90
Tail-log Backups
Question: What is the biggest advantage of being able to perform tail-log backups even when data files are damaged? Answer: The database can be fully recovered, without loosing any data.
91
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
92
Additional Reading
Backup Considerations
SQL Writer Service SQL Server 2005 Virtual Backup Device Interface (VDI) Specification A Guide for SQL Server Backup Application Vendors
Copy-only Backups
Copy-Only Backups
Tail-log Backups
Tail-Log Backups
93
Best Practices
Consider using CHECKSUM to create a checksum over your backup files. Use backup compression to increase backup and restore performance and safe storage space. Consider mirroring your backups to increase safety. Check if differential backup can speed up your restore process in full recovery mode. Use COPY_ONLY for out of sequence backups.
94
95
Module 7
Restoring SQL Server 2008 R2 Databases
Contents:
Lesson 1: Understanding the Restore Process Lesson 2: Restoring Databases Lesson 3: Working with Point-in-time recovery Lesson 4: Restoring System Databases and Individual Files Module Reviews and Takeaways Lab Review Questions and Answers 96 99 103 107 110 111
96
Lesson 1
97
98
Additional Reading
Types of Restores
Restore and Recovery Overview
99
Lesson 2
Restoring Databases
Contents:
Question and Answers Detailed Demonstration Steps Additional Reading 100 101 102
100
101
3. 4. 5.
102
Additional Reading
Phases of the Restore Process
Understanding How Restore and Recovery of Backups Work in SQL Server
Restoring a Database
How to: Restore a Differential Database Backup (SQL Server Management Studio) How to: Restore a Differential Database Backup (Transact SQL)
103
Lesson 3
104
STOPAT Option
Question: Why might you need to recover a database to a specific point in time? Answer: If data was deleted through a software failure or a user error.
STOPATMARK Option
Question: Why might STOPAT not be a good choice for synchronizing the restore of several databases and that STOPATMARK might be preferred? Answer: Because the time on the different instances might be out of sync.
105
2. 3.
Open and execute the 31 Demonstration 3A.sql script file from within Solution Explorer. Follow the instructions contained within the comments of the script file
106
Additional Reading
Overview of Point-in-time Recovery
Best Practices for Recovering a Database to a Specific Recovery Point Restore Under the Bulk-Logged Recovery Model
STOPAT Option
Recovering to a Specific Point in Time
STOPATMARK Option
Using Marked Transactions (Full Recovery Model) Recovering to a Marked Transaction
107
Lesson 4
108
2. 3.
Open and execute the 41 Demonstration 4A.sql script file from within Solution Explorer. Follow the instructions contained within the comments of the script file
109
Additional Reading
Restoring the master Database
How to Restore the master Database (Transact-SQL) Considerations for Restoring the master Database
110
Best Practices
Dont forget to backup the tail of the log before starting a restore sequence. Use differential restore to fasten the restore process if available. Use file level restore to speed up restores when not all database files are corrupt. Perform regular database backups of master, msdb and model system databases. Create a disaster recovery plan for your SQL Server and test restoring databases regularly.
111
112
Module 8
Importing and Exporting Data
Contents:
Lesson 1: Transferring Data To/From SQL Server Lesson 2: Importing & Exporting Table Data Lesson 3: Inserting Data in Bulk Module Reviews and Takeaways Lab Review Questions and Answers 113 117 121 125 126
113
Lesson 1
114
115
3. 4. 5.
116
Additional Reading
Overview of Data Transfer
Scenarios for Bulk Importing and Exporting Data
117
Lesson 2
118
119
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
2. 3.
Open the 22 Demonstration 2B.sql script file. Follow the instructions contained within the comments of the script file.
120
Additional Reading
Overview of SQL Server Integration Services
Typical Uses of Integration Services Tools and Utilities Overview (Integration Services)
121
Lesson 3
122
OPENROWSET Function
Question: When will it make sense to use OPENROWSET instead of bcp or BULK INSERT? Answer: When the data must be filtered before inserted into a table.
123
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
2. 3.
Open the 32 Demonstration 3B.sql script file. Follow the instructions contained within the comments of the script file.
2. 3.
Open the 33 Demonstration 3C.sql script file. Follow the instructions contained within the comments of the script file.
124
Additional Reading
BCP Utility
bcp Utility
OPENROWSET Function
OPENROWSET (Transact-SQL)
125
Best Practices
Choose the right tool for bulk-imports Use SSIS for complex transformations. Use bcp or BULK INSERT for fast imports and exports. Use OPENROWSET when data need to be filtered before it gets inserted. Try to achieve minimal logging to speed up data import
126
127
Module 9
Authenticating and Authorizing Users
Contents:
Lesson 1: Authenticating Connections to SQL Server Lesson 2: Authorizing Logins to Access Databases Lesson 3: Authorization Across Servers Module Reviews and Takeaways Lab Review Questions and Answers 128 132 136 140 141
128
Lesson 1
129
130
3. 4. 5.
131
Additional Reading
Overview of SQL Server Security
Securing SQL Server
132
Lesson 2
133
134
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
135
Additional Reading
Authorization Overview
Identity and Access Control (Database Engine)
136
Lesson 3
137
138
2.
Open the 31 Demonstration 3A.sql script file and follow the instructions contained within the comments of the script file.
139
Additional Reading
Typical "Double-Hop" Problem
How to Implement Kerberos Constrained Delegation with SQL Server 2008
140
Best Practices
Minimize the number of SQL Server logins. Ensure that expiry dates are applied to logins that are created for temporary purposes. Disable logins rather than dropping them if there is any chance that they will be needed again. Configure Kerberos delegation when a Windows user identity needs to be passed between systems.
141
142
Module 10
Assigning Server and Database Roles
Contents:
Lesson 1: Working with Server Roles Lesson 2: Working with Fixed Database Roles Lesson 3: Creating User-defined Database Roles Module Reviews and Takeaways Lab Review Questions and Answers 143 147 151 154 155
143
Lesson 1
144
145
3. 4. 5.
146
Additional Reading
Server-scoped Permissions
GRANT (Transact-SQL) Server-Level Roles
147
Lesson 2
148
149
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
150
Additional Reading
Database-scoped Permissions
Database-Level Roles Permissions of Fixed Database Roles (Database Engine) Permissions (Database Engine)
Database Owner
For more information about the Special Users, see Glossary definitions for Special Users
151
Lesson 3
152
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file to execute each T-SQL batch contained in the file.
2. 3.
Open the 32 Demonstration 3B.sql script file. Follow the instructions contained within the comments of the script file to execute each T-SQL batch contained in the file.
153
Additional Reading
Working with User-defined Database Roles
CREATE ROLE (Transact-SQL) Database-Level Roles
154
Best Practices
Avoid granting more permissions than are necessary. It is very common to see SQL Server systems where excessive permissions have been granted. Often the installers for applications will assume the need for much higher level permissions than should be necessary. Users should push back on vendors who do this. Even better, make appropriate security and permissions configuration a criterion for vendors to meet.
155
156
Module 11
Authorizing Users to Access Resources
Contents:
Lesson 1: Authorizing User Access to Objects Lesson 2: Authorizing Users to Execute Code Lesson 3: Configuring Permissions at the Schema Level Module Reviews and Takeaways Lab Review Questions and Answers 157 161 165 169 170
157
Lesson 1
158
159
3. 4. 5.
160
Additional Reading
What Are Principals?
Principals (Database Engine)
Column-level Security
GRANT Object Permissions (Transact-SQL)
161
Lesson 2
162
163
2.
3. Follow the instructions contained within the comments of the script file.
164
Additional Reading
Securing Stored Procedures
GRANT Object Permissions (Transact-SQL) How to: Grant Permissions on a Stored Procedure (SQL Server Management Studio)
165
Lesson 3
166
167
2.
3. Follow the instructions contained within the comments of the script file.
168
Additional Reading
Overview of User-schema Separation
User-Schema Separation CREATE SYNONYM (Transact-SQL)
169
Best Practices
Always assign the least possible privileges that users need. Test code as a standard user instead of testing as an administrator. Use EXECUTE AS and REVERT for quick testing of user permissions.
170
171
Module 12
Auditing SQL Server Environments
Contents:
Lesson 1: Options for Auditing Data Access in SQL Lesson 2: Implementing SQL Server Audit Lesson 3: Managing SQL Server Audit Module Reviews and Takeaways Lab Review Questions and Answers 172 176 180 184 185
172
Lesson 1
173
174
3. 4. 5.
175
Additional Reading
C2 Audit Mode
c2 audit mode Option
176
Lesson 2
177
Creating Audits
Question: Why is it recommended to select the option to shut down server on audit failure? Answer: To avoid actions occurring without being audited.
178
2.
3. Follow the instructions contained within the comments of the script file.
179
Additional Reading
Introduction to Extended Events
Introducing SQL Server Extended Events
Creating Audits
Audits (General Page) CREATE SERVER AUDIT (Transact-SQL)
180
Lesson 3
181
182
2.
3. Follow the instructions contained within the comments of the script file.
183
Additional Reading
Retrieving Audits
sys.fn_get_audit_file (Transact-SQL)
184
Best Practices
Choose the option to shut down SQL Server on audit failure. There is usually no point in setting up auditing and then having situations where events can occur but are not audited. This is particularly important in higher-security environments. Make sure that file audits are placed on drives with large amounts of free disk space and make sure that the available disk space is monitored on a regular basis.
185
186
Module 13
Automating SQL Server 2008 R2 Management
Contents:
Lesson 1: Automating SQL Server Management Lesson 2: Working with SQL Server Agent Lesson 3: Managing SQL Server Agent Jobs Module Reviews and Takeaways Lab Review Questions and Answers 187 191 195 199 200
187
Lesson 1
188
189
3. 4. 5.
190
Additional Reading
Benefits of Automating SQL Server Management
Automating Administrative Tasks (SQL Server Agent)
191
Lesson 2
192
Scripting Jobs
Question: In which scenarios might it be useful to script more than one job at a time. Answer: When all jobs need to be transferred to a new system.
193
2.
3. Follow the instructions contained within the comments of the script file.
194
Additional Reading
Defining Jobs, Job Step Types and Job Categories
Implementing Jobs
Scripting Jobs
How to: Script Jobs Using Transact-SQL (SQL Server Management Studio)
195
Lesson 3
196
197
2.
3. Follow the instructions contained within the comments of the script file.
198
Additional Reading
Viewing Job History
How to: Resize the Job History Log (SQL Server Management Studio) How to: View the Job History (SQL Server Management Studio)
199
Best Practices
Use SQL Agent jobs to schedule routine jobs. Define Alerts to respond to Events. Create custom categories to group your jobs. Script your jobs for remote deployment. Use job history to review job and job step outcomes. Use Job Activity Monitor to real time monitor jobs.
200
201
Module 14
Configuring Security for SQL Server Agent
Contents:
Lesson 1: Understanding SQL Server Agent Security Lesson 2: Configuring Credentials Lesson 3: Configuring Proxy Accounts Module Reviews and Takeaways Lab Review Questions and Answers 202 206 210 214 215
202
Lesson 1
203
204
3. 4. 5.
205
Additional Reading
Overview of SQL Server Agent Security
Selecting an Account for the SQL Server Agent Service Connecting to SQL Server by Using SQL Server Agent Service
206
Lesson 2
Configuring Credentials
Contents:
Question and Answers Detailed Demonstration Steps Additional Reading 207 208 209
207
Managing Credentials
Question: What happens when the Windows user password that a credential maps to changes or expires? Answer: The credential will stop working and the credential secret needs to be changed.
208
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
209
Additional Reading
Overview of Credentials
Credentials (Database Engine)
Configuring Credentials
CREATE CREDENTIAL (Transact-SQL)
Managing Credentials
ALTER CREDENTIAL (Transact-SQL) DROP CREDENTIAL (Transact-SQL)
210
Lesson 3
211
212
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
213
Additional Reading
Overview of Proxy Accounts
Creating SQL Server Agent Proxies
214
Best Practices
Use a Windows domain user to start SQL Server Agent service account. Use an account with least privileges. Create proxies with least permissions assigned for job execution.
215
216
Module 15
Monitoring SQL Server 2008 R2 with Alerts and Notifications
Contents:
Lesson 1: Configuration of Database Mail Lesson 2: Monitoring SQL Server Errors Lesson 3: Configuring Operators, Alerts and Notifications Module Reviews and Takeaways Lab Review Questions and Answers 217 221 225 229 230
217
Lesson 1
218
219
3. 4. 5.
220
Additional Reading
Overview of Database Mail
Database Mail Planning for Database Mail Database Mail Architecture
221
Lesson 2
222
Error Severity
Question: In which of the error number ranges shown on the slide, would you expect to see a syntax error? Answer: 11-16 as it can be corrected by the user, raised it. Actually it is level 15.
223
2.
3. Follow the instructions contained within the comments of the script file.
224
Additional Reading
What is in an Error?
Understanding Database Engine Errors System Error Messages sys.messages (Transact-SQL)
Error Severity
Database Engine Error Severities
225
Lesson 3
226
Create an Alert
Question: What type of alert would be needed to monitor free space in file system? Answer: WMI Alerts.
227
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
2.
3. Follow the instructions contained within the comments of the script file.
228
Additional Reading
SQL Server Agent Operator Overview
Components of Automatic Administration Defining Operators
Create an Alert
Defining Alerts sp_add_alert (Transact-SQL)
229
Best Practices
Use Database Mail and not SQL Mail Configure different profiles for different usage scenarios. Provide limited access to the ability to send emails from the database engine. Implement a retention policy for database mail log and mail auditing. Create operators to send notifications about Jobs and Alerts. Define Alerts for severe error messages.
230
231
Module 16
Performing Ongoing Database Maintenance
Contents:
Lesson 1: Ensuring Database Integrity Lesson 2: Maintaining Indexes Lesson 3: Automating Routine Database Maintenance Module Reviews and Takeaways Lab Review Questions and Answers 232 236 241 245 246
232
Lesson 1
233
234
3. 4. 5.
235
Additional Reading
Overview of DBCC CHECKDB
DBCC CHECKDB (Transact-SQL) DBCC CHECKALLOC (Transact-SQL) DBCC CHECKTABLE (Transact-SQL) DBCC CHECKCATALOG (Transact-SQL)
236
Lesson 2
Maintaining Indexes
Contents:
Question and Answers Detailed Demonstration Steps Additional Reading 237 239 240
237
Index Fragmentation
Question: Why does fragmentation affect performance? Answer: If pages are only half full, twice as many pages need to be read to access the same amount of data.
238
Updating Statistics
Question: Why might you decide to update statistics out of hours instead of automatically? Answer: That there is smaller chance that they get outdated during peak hours and need to be rebuild then.
239
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
240
Additional Reading
How Indexes Affect Performance
Table and Index Organization Which is Faster: Index Access or Table Scan?
Index Fragmentation
Reorganizing and Rebuilding Indexes
Updating Statistics
UPDATE STATISTICS (Transact-SQL) Using Statistics to Improve Query Performance sp_updatestats (Transact-SQL)
241
Lesson 3
242
243
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
244
Additional Reading
Overview of SQL Server Database Maintenance Plans
Maintenance Plan Wizard Maintenance Plans
245
Best Practices
Run DBCC CHECKDB regularly Synchronize DBCC CHECKDB with your backup strategy Consider RESTORE before repairing if corruption occurs Defragment your indexes when necessary Update statistics on schedule, if you dont want it to occur during normal operations Use Maintenance Plans to implement regular tasks
246
247
Module 17
Tracing Access to SQL Server 2008 R2
Contents:
Lesson 1: Capturing Activity using SQL Server Profiler Lesson 2: Improving Performance with the Database Engine Tuning Advisor Lesson 3: Working with Tracing Options Module Reviews and Takeaways Lab Review Questions and Answers 248 252 256 260 261
248
Lesson 1
249
Filtering Traces
Question: What filter would you use to locate long running batches or statements? Answer: A filter on the Duration column.
250
3. 4. 5.
251
Additional Reading
Overview of SQL Server Profiler
Using SQL Server Profiler Typical Uses of SQL Server Profiler SQL Server Profiler Terminology
Filtering Traces
How to: Filter Events in a Trace (SQL Server Profiler)
252
Lesson 2
253
254
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
255
Additional Reading
Overview of Performance Tuning
Performance Monitoring and Tuning How-to Topics Monitoring and Tuning for Performance Overview
256
Lesson 3
257
Retrieving Traces
Question: When might it be a good idea to test systems using the replay functionality? Answer: When it is not possible to test the real application with a realistic workload.
Default Trace
Question: Should the default trace be kept enabled? Answer: Yes.
258
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
Demonstration 3B: Combining Traces with Performance Monitor Logs Demonstration Steps
1. If Demonstration 1A was not performed: Revert the virtual machines as per the instructions in D:\6231B_Labs\Revert.txt. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, clickSQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_17_PRJ\6231B_17_PRJ.ssmssln and click Open. Open and execute the 00 Setup.sql script file from within Solution Explorer.
2. 3.
Open the 32 Demonstration 3B.sql script file. Follow the instructions contained within the comments of the script file.
259
Additional Reading
Overview of SQL Trace
Introducing SQL Trace
Replaying Traces
Replaying Traces Description of the Replay Markup Language (RML) Utilities for SQL Server
Default Trace
default trace enabled (Option)
260
Best Practices
Use SQL Server Profiler to perform short traces for debugging and other purposes Use SQL Trace for large and long running traces Use SQL Server Profiler to define traces and script them for SQL Trace Import trace data into a database table for advanced analysis Use Database Engine Tuning Advisor to analyze the database based on a workload rather than focusing on individual queries
261
262
Module 18
Monitoring SQL Server 2008 R2
Contents:
Lesson 1: Monitoring Activity Lesson 2: Capturing and Managing Performance Data Lesson 3: Analyzing Collected Performance Data Module Reviews and Takeaways Lab Review Questions and Answers 263 267 271 276 277
263
Lesson 1
Monitoring Activity
Contents:
Question and Answers Detailed Demonstration Steps Additional Reading 264 265 266
264
265
3. 4. 5.
Demonstration 1B: Working with Activity Monitor in SQL Server Management Studio Demonstration Steps
1. If Demonstration 1A was not performed: Revert the virtual machines as per the instructions in D:\6231B_Labs\Revert.txt. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, clickSQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_18_PRJ\6231B_18_PRJ.ssmssln and click Open. Open and execute the 00 Setup.sql script file from within Solution Explorer.
2. 3.
Open the 12 Demonstration 1B.sql script file. Follow the instructions contained within the comments of the script file.
Demonstration 1C: Working with Reliability and Performance Monitor Demonstration Steps
1. If Demonstration 1A was not performed: Revert the virtual machines as per the instructions in D:\6231B_Labs\Revert.txt. In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, clickSQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_18_PRJ\6231B_18_PRJ.ssmssln and click Open. Open and execute the 00 Setup.sql script file from within Solution Explorer.
2. 3.
Open the 13 Demonstration 1C.sql script file. Follow the instructions contained within the comments of the script file.
266
Additional Reading
Overview of Dynamic Management Views and Functions
Dynamic Management Views and Functions(Transact-SQL)
267
Lesson 2
268
269
2. 3.
Open the 21 Demonstration 2A.sql script file. Follow the instructions contained within the comments of the script file.
270
Additional Reading
Overview of Data Collector
Introducing Data Collector
271
Lesson 3
272
273
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
2. 3.
Open the 32 Demonstration 3B.sql script file. Follow the instructions contained within the comments of the script file.
274
2. 3.
Open the 33 Demonstration 3C.sql script file. Follow the instructions contained within the comments of the script file.
275
Additional Reading
Overview of Data Collector Reports
How to: View a Collection Set Report
276
Best Practices
Use Dynamic Management Objects to perform real-time monitoring and troubleshooting. Use Activity Monitor for easy access to the most relevant information. Use Reliability and Performance Monitor to gather metrics for Windows and SQL Server. Create a central Management Data Warehouse to hold historical performance information. Set up data collection to gather performance data of your SQL Server Instances.
277
278
Module 19
Monitoring SQL Server 2008 R2
Contents:
Lesson 1: Working with Multiple Servers Lesson 2: Virtualizing SQL Server Lesson 3: Deploying and Upgrading Data-Tier Applications Module Reviews and Takeaways Lab Review Questions and Answers 279 283 286 290 291
279
Lesson 1
280
281
3. 4. 5.
282
Additional Reading
Overview of Central Management Servers
Administering Multiple Servers Using Central Management Servers
283
Lesson 2
284
285
Additional Reading
Overview of SQL Server Virtualization
SQL Server 2008 Virtualization
286
Lesson 3
287
288
2. 3.
Open the 31 Demonstration 3A.sql script file. Follow the instructions contained within the comments of the script file.
289
Additional Reading
Data-tier Application Overview
Understanding Data-tier Applications
290
Best Practices
Use Central Management Server to maintain a central configuration of registered servers and groups Use multi-server queries to run batches against several servers concurrently Consider virtualization for high availability, consolidation, better hardware utilization, and test environments Consider the use of data-tier application for departmental database applications
291
292
Module 20
Troubleshooting Common SQL Server 2008 R2 Administrative Issues
Contents:
Lesson 1: SQL Server Troubleshooting Methodology Lesson 2: Resolving Service-related Issues Lesson 3: Resolving Concurrency Issues Lesson 4: Resolving Login and Connectivity Issues Module Reviews and Takeaways Lab Review Questions and Answers 293 296 300 304 307 308
293
Lesson 1
294
Question: What characteristics do you notice in people that are poor trouble-shooters? Answer: Answers will vary but common characteristics are: Follows a haphazard approach that does not follow a logical path Becomes more illogical the more that stress is applied Makes assumptions that are not supportable Quickly decides upon a cause for problems, without justification, and then tries to justify the selection of the cause Assumes problems are resolved without justification
295
Additional Reading
Discussion: Characteristics of Good Trouble-shooters
Troubleshooting Concepts
296
Lesson 2
297
298
3. 4. 5.
299
Additional Reading
Troubleshooting Service-related Issues
How to: Start an Instance of SQL Server (sqlservr.exe) Setting Up Windows Service Accounts
300
Lesson 3
301
Troubleshooting Blocking
Question: What do you suspect that "excessive" blocking might refer to? Answer: An example would be a program that is not returning an error but is not making any progress. Another might be web pages that are timing out while accessing the database, without returning an error from the database.
Troubleshooting Deadlocks
Question: Have you experienced deadlocking problems in your current environment? If so, how did you determine that deadlocks were a problem, and how was it resolved? Answer: Answers will vary but users have often seen deadlock related error messages.
302
In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, clickSQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_20_PRJ\6231B_20_PRJ.ssmssln and click Open. Open and execute the 00 Setup.sql script file from within Solution Explorer. Open the 31 Demonstration 3A.sql script file from within Solution Explorer. Follow the instructions contained within the comments of the script file.
3. 4. 5.
In the virtual machine, click Start, click All Programs, click Microsoft SQL Server 2008 R2, clickSQL Server Management Studio. In the Connect to Server window, type Proseware and click Connect. From the File menu, click Open, click Project/Solution, navigate to D:\6231B_Labs\6231B_20_PRJ\6231B_20_PRJ.ssmssln and click Open. Open and execute the 00 Setup.sql script file from within Solution Explorer. Open the 32 Demonstration 3B.sql script file. Follow the instructions contained within the comments of the script file.
3. 4. 5.
303
Additional Reading
Core Concurrency Concepts
Isolation Levels in the Database Engine Types of Concurrency Control Concurrency Effects
Troubleshooting Blocking
INF: Understanding and resolving SQL Server blocking problems
Troubleshooting Deadlocks
Deadlocking
304
Lesson 4
305
306
Additional Reading
Troubleshooting Connectivity Issues
Troubleshooting Database Engine Connectivity
307
Best Practices
Monitor your system and store historical data using Data Collector for example for easier troubleshooting Clearly identify underlying problems rather than fighting symptoms Apply deadlock monitoring using SQL Trace
308
309
Courseware Feedback
Send all courseware feedback to msupport@mscourseware.com. We truly appreciate your time and effort. We review every e-mail received and forward the information on to the appropriate team. Unfortunately, because of volume, we are unable to provide a response but we may use your feedback to improve your future experience with Microsoft Learning products.
Reporting Errors
When providing feedback, include the training product name and number in the subject line of your email. When you provide comments or report bugs, please include the following: 1. 2. 3. Document or CD part number Page number or location Complete description of the error or suggested change
Please provide any details that are necessary to help us verify the issue. Important All errors and suggestions are evaluated, but only those that are validated are added to the product Knowledge Base article.