Beginning SQL Server 2008 Administration ..... Step 2: Understanding the SQL
Server Installation Center . ... Step 3: Installing an Instance of SQL Server .
Beginning SQL Server 2008 Administration
■■■ Robert E. Walters, Grant Fritchey, and Carmen Taglienti
Beginning SQL Server 2008 Administration Copyright © 2009 by Robert E. Walters, Grant Fritchey, and Carmen Taglienti All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2413-6 ISBN-13 (electronic): 978-1-4302-2414-3 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. Lead Editor: Jonathan Gennick Technical Reviewer: Richard Waymire Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Michelle Lowman, Matthew Moodie, Jeffrey Pepper, Frank Pohlmann, Ben RenowClarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Managers: Beth Christmas and Debra Kelly Copy Editor: Kim Wimpsett Compositor: v-prompt Indexer: Barbara Pulumbo Artist: April Milne Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail
[email protected], or visit http://www.springeronline.com. For information on translations, please e-mail
[email protected], or visit http://www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales—eBook Licensing web page at http://www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work.
ii
INTRODUCITON
Contents at a Glance
■About the Authors........................................................................................ xvi ■About the Technical Reviewer ...................................................................xvii ■Acknowledgments ....................................................................................... xix ■Introduction ................................................................................................. xx ■Chapter 1: The Database Administration Profession ...................................1 ■Chapter 2: Planning and Installing SQL Server 2008 ...................................9 ■Chapter 3: What’s in the Toolbox? ...............................................................41 ■Chapter 4: Creating Tables and Other Objects............................................75 ■Chapter 5: Transact-SQL ..............................................................................97 ■Chapter 6: SQL Server Internals ................................................................117 ■Chapter 7: Storage Management Strategies ..............................................127 ■Chapter 8: Database Backup Strategies.....................................................151 ■Chapter 9: Database Restore Strategies.....................................................183 ■Chapter 10: Common Database Maintenance Tasks ...............................211 ■Chapter 11: Automation Through SQLCMD and PowerShell...................239 ■Chapter 12: Database Maintenance Plans.................................................263 ■Chapter 13: Performance Tuning and Optimization ................................287 ■Chapter 14: SQL Server Security ................................................................327 ■Chapter 15: Auditing, Encryption, and Compliance.................................347 ■Chapter 16: SQL Server in the Enterprise..................................................373 ■Chapter 17: Where to Go Next? ..................................................................395 ■Index ...........................................................................................................401
iii
INTRODUCITON
Contents ■About the Authors........................................................................................ xvi ■About the Technical Reviewer ...................................................................xvii ■Acknowledgments ...................................................................................xxviii ■Introduction ................................................................................................. xx Who This Book Is For ................................................................................................................................. xxi How This Book Is Structured ..................................................................................................................... xxi Getting the Most from This Book ............................................................................................................ xxiii Errata ......................................................................................................................................................... xxiii Contacting the Authors ........................................................................................................................... xxiiii
■Chapter 1: The Database Administration Profession ...................................1 Why Do We Need a DBA? Access Runs Great! ............................................................................................. 1 What Exactly Does a DBA Do Anyway? ........................................................................................................ 2 Database Maintenance ............................................................................................................................ 2 Security and Regulatory Compliance...................................................................................................... 3 Disaster Recovery ..................................................................................................................................... 3 Design and Performance Improvement ................................................................................................. 3 Documentation......................................................................................................................................... 4 Salary Information ........................................................................................................................................ 4 Words from Real-World DBAs ...................................................................................................................... 4 Grant Fritchey, Principal DBA ................................................................................................................. 4 Roman Rehak, Principal Database Architect.......................................................................................... 6 Summary ........................................................................................................................................................ 8
v
■ CONTENTS
■Chapter 2: Planning and Installing SQL Server 2008 ...................................9 Understanding the Editions ......................................................................................................................... 9 Demystifying 32-Bit and 64-Bit Architectures...................................................................................... 10 Server Editions ........................................................................................................................................ 10 SQL Server Terminology ........................................................................................................................ 12 Planning Your Installation .......................................................................................................................... 12 Assessing the Environment.................................................................................................................... 13 Choosing the Right Edition .................................................................................................................... 15 Validating Hardware and Software Requirements............................................................................... 16 Installing SQL Server Evaluation Edition................................................................................................... 16 Step 1: Downloading SQL Server Evaluation Edition........................................................................... 16 Step 2: Understanding the SQL Server Installation Center ................................................................. 17 Step 3: Installing an Instance of SQL Server ......................................................................................... 26 Upgrading SQL Server................................................................................................................................. 35 A Word from the SQL Server Setup Team.................................................................................................. 38 Summary ...................................................................................................................................................... 39
■Chapter 3: What’s in the Toolbox? ...............................................................41 SQL Server Management Studio ................................................................................................................ 41 Connecting to SQL Server ...................................................................................................................... 41 Issuing Queries Using SSMS ................................................................................................................. 44 Managing Multiple Servers .................................................................................................................... 51 Monitoring Server Activity ..................................................................................................................... 53 Other Tools from the Start Menu ............................................................................................................... 59 Analysis Services Folder ......................................................................................................................... 60 Configuration Tools Folder.................................................................................................................... 61 Documentation and Tutorials Folder ................................................................................................... 66 Integration Services Folder .................................................................................................................... 67 Performance Tools Folder...................................................................................................................... 68 Command-Line Tools ................................................................................................................................. 69 SQLCMD.................................................................................................................................................. 69 PowerShell Provider for SQL Server ...................................................................................................... 71
vi
■ CONTENTS
Summary ...................................................................................................................................................... 72
■Chapter 4: Creating Tables and Other Objects............................................75 Navigating the Object Explorer Tree.......................................................................................................... 75 Scripting the Actions of an SSMS Dialog Box ............................................................................................ 76 Transact-SQL (T-SQL) Primer .................................................................................................................... 79 Data Definition Language (DDL) .......................................................................................................... 80 Data Manipulation Language (DML) .................................................................................................... 80 Data Control Language (DCL) ............................................................................................................... 81 Creating Tables............................................................................................................................................ 82 Creating Tables from the Table Designer ............................................................................................. 82 Issuing the CREATE TABLE Statement ................................................................................................. 83 Altering Tables ............................................................................................................................................. 85 Adding Constraints...................................................................................................................................... 85 NULL Constraints................................................................................................................................... 85 CHECK Constraints ................................................................................................................................ 86 Primary Key and Unique Constraints ................................................................................................... 86 Foreign Key Constraints......................................................................................................................... 87 Dropping Tables .......................................................................................................................................... 88 Creating Indexes.......................................................................................................................................... 90 Summary ...................................................................................................................................................... 94
■Chapter 5: Transact-SQL ..............................................................................97 The VetClinic Sample Database Revisited................................................................................................. 97 Data Types ................................................................................................................................................... 98 Unicode vs. ANSI .................................................................................................................................... 99 Living with NULL.................................................................................................................................. 100 Data Manipulation Language................................................................................................................... 100 SELECT .................................................................................................................................................. 100 INSERT .................................................................................................................................................. 103 UPDATE ................................................................................................................................................ 103 DELETE ................................................................................................................................................. 104 Transactions .............................................................................................................................................. 104
vii
■ CONTENTS
Execution............................................................................................................................................... 104 Transaction Isolation ........................................................................................................................... 105 Deadlocks.............................................................................................................................................. 106 Stored Procedures ..................................................................................................................................... 108 Creating Stored Procedures Using Templates.................................................................................... 109 Modifying Stored Procedures .............................................................................................................. 112 System Stored Procedures ................................................................................................................... 112 Functions ................................................................................................................................................... 113 Creating a Function .............................................................................................................................. 113 Invoking a Function ............................................................................................................................. 113 Triggers....................................................................................................................................................... 114 Summary .................................................................................................................................................... 115
■Chapter 6: SQL Server Internals ................................................................117 Databases ................................................................................................................................................... 117 Master Database ................................................................................................................................... 117 Tempdb Database ................................................................................................................................ 117 Model Database .................................................................................................................................... 118 MSDB Database .................................................................................................................................... 118 Resource Database ............................................................................................................................... 119 Repairing Corrupt System Databases ...................................................................................................... 119 Writing Data to Disk .................................................................................................................................. 119 SQL Server Services ................................................................................................................................... 120 Single-User Mode...................................................................................................................................... 122 Placing an Already-Started Database into Single-User Mode........................................................... 122 Starting SQL Server in Single-User Mode ........................................................................................... 123 Summary .................................................................................................................................................... 126
■Chapter 7: Storage Management Strategies ..............................................127 Storage Systems ......................................................................................................................................... 127 Storage System Interfaces......................................................................................................................... 129 IDE ATA ................................................................................................................................................. 129 SATA ...................................................................................................................................................... 129
viii
■ CONTENTS
SCSI........................................................................................................................................................ 129 Serial Attached SCSI ............................................................................................................................. 129 Fibre Channel Direct Attached Storage .............................................................................................. 130 Fibre Channel Storage Area Network.................................................................................................. 130 iSCSI....................................................................................................................................................... 130 InfiniBand ............................................................................................................................................. 130 Storage System Types................................................................................................................................ 130 Direct Attached Storage ....................................................................................................................... 130 Storage Area Network........................................................................................................................... 131 Network Attached Storage ................................................................................................................... 133 Figure 7-3. NAS architecture ................................................................................................................... 134 Disk Configuration: RAID ......................................................................................................................... 135 RAID 0 (Striping)................................................................................................................................... 135 RAID 1 (Mirroring and Duplexing) ...................................................................................................... 135 RAID 10 (Stripe of Mirrors) .................................................................................................................. 136 RAID 5 (Striping with Parity)................................................................................................................ 137 Hardware and Software RAID................................................................................................................... 139 Selecting a Storage System for SQL Server 2008...................................................................................... 139 I/O Performance ................................................................................................................................... 139 Redundancy Is Critical ......................................................................................................................... 141 Configuring Your Database ...................................................................................................................... 145 Data Compression ................................................................................................................................ 147 Disk Volume Alignment ....................................................................................................................... 149 Summary .................................................................................................................................................... 149
■Chapter 8: Database Backup Strategies.....................................................151 Defining the Types of Backups ................................................................................................................. 151 Full Backups.......................................................................................................................................... 152 Differential Backups ............................................................................................................................. 158 File and Filegroup Backups.................................................................................................................. 159 Backing Up the Logs.................................................................................................................................. 161 Initiating Fully Recovery Mode............................................................................................................ 162 Log Backup Using Management Studio.............................................................................................. 163
ix
■ CONTENTS
Log Backup Using T-SQL ..................................................................................................................... 164 Backing Up a Copy of the Database .................................................................................................... 164 Automating the Backup Process............................................................................................................... 164 Encrypting Backup Files for Security ....................................................................................................... 176 Compressing Backups to Save Space....................................................................................................... 177 Designing a Backup Plan .......................................................................................................................... 180 Summary .................................................................................................................................................... 182
■Chapter 9: Database Restore Strategies.....................................................183 Restoring a Database from the Management Studio GUI...................................................................... 183 Specifying Restore Options from the GUI ............................................................................................... 191 Restoring a Database Using T-SQL .......................................................................................................... 193 Executing a Simple Restore.................................................................................................................. 193 Creating a Copy of a Database............................................................................................................. 194 Retrieving Logical and Physical File Names ....................................................................................... 195 Displaying General Information About a Backup .............................................................................. 197 Cleaning Up .......................................................................................................................................... 198 Restoring Differential Backups................................................................................................................. 198 Restoring Log Backups.............................................................................................................................. 200 Restoring File Backups.............................................................................................................................. 204 Testing Backups......................................................................................................................................... 206 Developing a Full Disaster Recovery Plan ............................................................................................... 207 Gathering Information About the Business........................................................................................ 207 Establishing the Disaster Plan ............................................................................................................. 208 Testing the Disaster Plan...................................................................................................................... 209 Summary .................................................................................................................................................... 210
■Chapter 10: Common Database Maintenance Tasks ...............................211 Backing Up and Restoring ........................................................................................................................ 211 Checking the Database Integrity .............................................................................................................. 211 Shrinking the Database............................................................................................................................. 214 Reorganizing and Rebuilding Indexes ..................................................................................................... 218 Detecting Undue Fragmentation ........................................................................................................ 218
x
■ CONTENTS
Rebuilding an Index ............................................................................................................................. 219 Reorganizing an Index.......................................................................................................................... 220 Getting Updated Statistics ........................................................................................................................ 220 Checking the Status of Automatic Statistics Gathering ..................................................................... 221 Manually Updating Statistics............................................................................................................... 221 Monitoring Logs ........................................................................................................................................ 222 Creating SQL Server Agent Jobs................................................................................................................ 225 Connecting to SQL Server .................................................................................................................... 226 Creating an Agent Job........................................................................................................................... 227 Defining Alerts ........................................................................................................................................... 233 Summary .................................................................................................................................................... 238
■Chapter 11: Automation Through SQLCMD and PowerShell...................239 Scripting in SQLCMD ................................................................................................................................ 239 Executing Commands Interactively......................................................................................................... 239 Executing Script in Batch Mode ............................................................................................................... 240 Testing SQLCMD Scripts .......................................................................................................................... 242 Using SQLCMD to Back Up a Database................................................................................................... 244 Generating Scripts from Management Studio ........................................................................................ 245 Scripting in PowerShell ............................................................................................................................. 247 Configuring PowerShell for Use With SQL Server .............................................................................. 248 Understanding the Components......................................................................................................... 250 Starting PowerShell in Interactive Mode ............................................................................................ 251 Specifying an Execution Policy............................................................................................................ 253 Executing a PowerShell Script Interactively ....................................................................................... 253 Running PowerShell Scripts in Batch Mode ....................................................................................... 257 Running PowerShell from SQL Server Agent...................................................................................... 258 Running PowerShell Scripts from Maintenance Plans ...................................................................... 259 Using the PowerShell Integrated Scripting Environment ................................................................. 260 Summary .................................................................................................................................................... 262
xi
■ CONTENTS
■Chapter 12: Database Maintenance Plans.................................................263 Understanding the Fundamentals........................................................................................................... 265 Creating a Maintenance Plan ................................................................................................................... 267 Starting the Maintenance Plan Wizard .................................................................................................... 267 Specifying Plan Properties ................................................................................................................... 268 Specifying Job Schedule Properties..................................................................................................... 269 Selecting Maintenance Tasks .............................................................................................................. 270 Selecting Maintenance Task Order ..................................................................................................... 271 Configuring Individual Tasks ................................................................................................................... 272 Check Database Integrity ..................................................................................................................... 272 Shrink Database.................................................................................................................................... 274 Reorganize Index .................................................................................................................................. 275 Rebuild Index ........................................................................................................................................ 276 Update Statistics ................................................................................................................................... 278 History Cleanup.................................................................................................................................... 279 Back Up Database (Full)....................................................................................................................... 279 Maintenance Cleanup.......................................................................................................................... 281 Select Report Options........................................................................................................................... 282 Completing the Maintenance Plan Wizard ............................................................................................. 282 Modifying an Existing Maintenance Plan................................................................................................ 284 Summary .................................................................................................................................................... 285
■Chapter 13: Performance Tuning and Optimization ................................287 Measuring SQL Server Performance ........................................................................................................ 287 Performance Counters ......................................................................................................................... 288 Performance Monitor........................................................................................................................... 289 Dynamic Management Views.............................................................................................................. 293 Data Collector ....................................................................................................................................... 295 Setting Up the Data Collector .............................................................................................................. 296 Viewing the Data Collector Data ......................................................................................................... 300 Tuning Queries .......................................................................................................................................... 308 Understanding Execution Plans .......................................................................................................... 308
xii
■ CONTENTS
Gathering Query Information with Profiler ........................................................................................ 315 Using the Database Engine Tuning Advisor ....................................................................................... 320 Managing Resources ................................................................................................................................. 323 Limiting Resource Use .............................................................................................................................. 323 Leveraging Data Compression ............................................................................................................ 325 Summary .................................................................................................................................................... 326
Chapter 14: SQL Server Security...................................................................327 Terminology............................................................................................................................................... 327 Authentication ...................................................................................................................................... 327 Authentication Mode ........................................................................................................................... 328 Authorization ........................................................................................................................................ 328 Server Instance vs. the Database ......................................................................................................... 328 SQL Server Instance Security.................................................................................................................... 330 Creating a SQL Server Login ................................................................................................................ 330 Server Roles........................................................................................................................................... 332 Server Permissions ............................................................................................................................... 333 Endpoints .............................................................................................................................................. 335 Database Security...................................................................................................................................... 337 Database Users ..................................................................................................................................... 337 Schemas ................................................................................................................................................ 337 Fixed Database Roles ............................................................................................................................... 340 Flexible Database Roles........................................................................................................................ 343 Security Functions................................................................................................................................ 344 Summary .................................................................................................................................................... 345
■Chapter 15: Auditing, Encryption, and Compliance.................................347 Auditing in SQL Server 2008 ..................................................................................................................... 348 Auditing Objects ................................................................................................................................... 349 Server Audit Object............................................................................................................................... 350 Server Audit Specification Object........................................................................................................ 352 Database Audit Specification Object................................................................................................... 356 Encryption ................................................................................................................................................. 358
xiii
■ CONTENTS
Encryption Primer ................................................................................................................................ 358 Password-Based Encryption ................................................................................................................ 359 Certificate-Based Encryption .............................................................................................................. 362 Transparent Data Encryption .............................................................................................................. 363 Validating Server Configuration............................................................................................................... 364 The Need for a Policy............................................................................................................................ 365 Create Policy on a Local Server............................................................................................................ 365 Evaluate the Policy................................................................................................................................ 368 Using the Central Management Server............................................................................................... 370 Summary .................................................................................................................................................... 371
■Chapter 16: SQL Server in the Enterprise..................................................373 Systems Center Operations Manager 2007.............................................................................................. 373 Installing the SQL Server SCOM Management Pack .............................................................................. 375 Getting Familiar with the SQL Server Management Pack ...................................................................... 378 Finding and Resolving an Issue................................................................................................................ 381 Using System Center Data Protection Manager ..................................................................................... 385 Setting Up a Protection Group ............................................................................................................ 387 Executing DPM Reports: ...................................................................................................................... 390 Recovering a Databases: ...................................................................................................................... 392 Summary .................................................................................................................................................... 394
■Chapter 17: Where to Go Next? ..................................................................395 Visit SQL Server Books Online .................................................................................................................. 395 Keep Up with Public SQL Server Websites .............................................................................................. 395 Attend a Conference.................................................................................................................................. 396 Find a Local Users Group.......................................................................................................................... 396 Create a Lab System and Practice ............................................................................................................ 396 Get Certified!.............................................................................................................................................. 399
■Index ...........................................................................................................401
xiv
■ ABOUT THE AUTHORS
About the Authors ■Rob Walters is a Data Platform Technology Specialist with Microsoft. He specializes in navigating customers through the powerful features and functionality of relational databases. Mr. Walters’ extensive experience with Microsoft SQL Server started more than 10 years ago when he worked as a consultant for Microsoft Consulting Services in Denver, CO. Shortly after the dotcom bubble burst, Mr. Walters returned to Microsoft’s headquarters and worked as a Program Manager in the SQL Server product unit. There he owned various features within SQL Server including SQL Server Agent, various management features, and the security for the database engine. Mr. Walters holds three patents on technologies that are used within SQL Server 2005 and SQL Server 2008. Mr. Walters has co-authored Programming Microsoft SQL Server 2005 (Microsoft Press, 2006) and Pro SQL Server 2005 (Apress, 2007). He is also the lead author of Accelerated SQL Server 2008 (Apress, 2008). Mr. Walters holds a Bachelors of Science in Electrical Engineering from Michigan State University and a Masters Degree in Business Administration from Seattle University.
■Grant Fritchey works for engineering and insurance company FM Global as a principal DBA. He’s done development of large-scale applications in languages such as VB, C#, and Java and has worked in SQL Server since Version 6.0. Grant is a Microsoft SQL Server MVP. He is the author of SQL Server 2008 Performance Tuning Distilled (Apress, 2009) and Dissecting SQL Server Execution Plans (Simple Talk Publishing, 2008).
xv
■ ABOUT THE AUTHORS
■Carmen Taglienti is currently a SQL Server/Business Intelligence Architect for Microsoft in the Microsoft Technology Center in Boston. Prior to Microsoft he managed a Business Intelligence for a Microsoft partner where he built large-scale data warehouse and analytic solutions using SQL Server. His academic background is in Systems Engineering and Computer Science. He has managed his own consulting business and early in his career worked as a 3D graphics programmer. Carmen spends a lot of time working with customers creating SQL Server platform solutions. He has published papers on data warehousing, frequently speaks at conferences, and teaches Microsoft Courses on Business Intelligence and SQL Server. Outside of work Carmen is a triathlete and enjoys coaching his son in the sport. He also loves to spend time with his wife, daughter, and two dogs.
xvi
■ ABOUT THE AUTHORS
About the Technical Reviewer ■Richard Waymire is a Principal program manager in the Microsoft SQL Server development team, where he has been a program manager for more than 11 years. He is a founding editor of SQL Server Magazine as well as the author of a number of books about SQL Server. Richard has been working on databases and software for more than 20 years, including working on DB2, Oracle, Teradata, and SQL Server (starting with version 4.21a).
xvii
■ ABOUT THE AUTHORS
Acknowledgments I would like to thank the following people for their generous time in providing guidance on the content for this book: Jeanne Fineout, David Gollob, and Don Watters. The efforts of these folks helped shape the content that you are about to learn and enjoy. This book was intended to not only give the reader some technical skills on typical DBA tasks but to also provide real-world insight into the typical lives of DBAs. A special thanks to the following industry professionals who provided their first-hand, real-world experiences and knowledge via interviews posted throughout this book: Peter Saddow, Roman Rehak, Grant Fritchey, and JC Cannon. Rob Walters
Thanks to Rob Walters for inviting me to help out with his book. It was an honor, and I hope I lived up to it. Thanks to all the people at Apress, again, especially Jonathan Gennick, for the opportunity and support. You guys are good. A nod must go to the denizens of SQL Server Central, especially The Thread, for all their help. Finally, always, to my wife and kids, thanks for letting me take time away from you to do these books. Grant Fritchey I’d like to thank my wife, Renee, and my kids, CJ and Tori, for putting up with my "I'll be five more minutes" statements, which they knew would be more like an hour. Carmen Taglienti
xviii
■ INTRODUCTION
Introduction The SQL Server product has been around since the late 1980s. Back then, Microsoft worked together with Sybase to create a database on the OS/2 platform. Shortly after this effort completed, Microsoft realized it wanted to tightly couple SQL Server with Windows. By 1993, Microsoft had released Windows NT 3.1, and with it came the option of using a well-integrated version of SQL Server called SQL Server 4.2. This was to be the last version of SQL Server made jointly between the two companies. By 1995, Microsoft left the partnership with Sybase and released SQL Server version 6.0, followed a year later by version 6.5. These two versions were still on the original Sybase platform. As a DBA today, it would be a rare occurrence to see a production server running any of these three versions of SQL Server. If you do, chances are the servers are probably running a database application from a company that no longer exists. Either way, if you encounter these systems in production, it may be worthwhile to do a few web searches and learn a bit more about how to administer these kinds of SQL Server instances. By 1997, Microsoft decided to rewrite the database engine and effectively move away from the old Sybase design. This rewrite effort led to the release of SQL Server’s next version, 7.0. To some, this version marked the first generation of SQL Server. By rewriting the database engine, Microsoft was able to provide key features to customers. Some of these advancements included the ability for offline users to update data and merge it back to live data when they reconnected to the server (merge replication). DBAs could also grow and shrink databases as needed as well as use new wizards such as the Copy Database Wizard to easily perform administrative tasks. SQL Server 7.0 also made Online Analytical Processing (OLAP) capabilities affordable to the market by including OLAP services as part of the SQL Server 7.0 license. This was SQL Server’s initial entry into the data warehousing market. With SQL Server 7.0, users could now easily design, build, and manage data marts and data warehouses. Seeing a SQL Server 7.0 in production isn’t as uncommon as an older version but is still rare since that version is no longer being serviced or supported by Microsoft. SQL Server 2000, released in 1999, built upon the success and lower total cost of ownership value that SQL Server 7.0 had introduced to the market. Major parts of the database engine were rewritten again to accommodate features such as multi-instances where DBAs could run more than one instance of SQL Server per server. Microsoft made continued investments in scalability and availability with features such as log shipping. Log shipping allowed DBAs to automatically copy and load transaction log backups from one database to one or more databases, enabling a highly available environment. Investments were also made for developers, including XML support and the ability to define userdefined functions. In the business intelligence (BI) space, a more mature version of Data Transformation Services was shipped as well as Reporting Services for SQL Server 2000. There was a large effort around the integration of Microsoft Office applications and Analysis Services. For example, it was possible to use Excel pivot tables loaded with data from cubes created with Analysis Services. Although SQL Server 2000 is currently in extended support, there are many organizations still using it in production today. There is a good chance you as a DBA will be involved with managing and eventually upgrading these servers to SQL Server 2008. Between the release of SQL Server 2000 and SQL Server 2005, there was about a five-year gap. The result of this long wait was a product that contained many new enterprise capabilities such as database mirroring, online indexing, online restore, table partitioning, and many others.
xix
■ INTRODUCTION
It is highly likely if your company is using SQL Server, it will probably have some installations of SQL Server 2005 in production. SQL Server 2008 is all about solving the problems that very large databases bring. Features such as data compression, resource governance, and enterprise-wide policy management headline the marketing brochures. Throughout the remainder of this book, you will be exposed to a lot of these key features of SQL Server 2008.
Who This Book Is For Are you considering a career as a database administrator? Are you an IT professional who is curious about what SQL Server is and how to manage it? Are you a database administrator for a non—SQL Server platform like Oracle or DB2 and have an interest in SQL Server? Do you want to learn about SQL Server? If you answered “yes” to any of these questions, then you will have invested your money wisely in this book. This book provides you with a solid foundation of the fundamental skills and concepts of managing a SQL Server instance.
How This Book Is Structured For those readers who are not familiar with databases, it is probably best to work through each chapter sequentially since topics in later chapters build on ones described in earlier chapters. This is what each chapter covers: Chapter 1: This chapter explores the database administration profession. Topics include typical tasks of DBAs as well as input from experienced real-life DBAs. Chapter 2: SQL Server is an enterprise-ready database platform. Simply installing it onto a production server without much planning is a surefire way to getting shown the door by your current employer. This chapter explores some of the key issues to consider when installing SQL Server. Microsoft provides multiple editions of SQL Server. This chapter also reviews these editions as well as walks you through an installation of the evaluation edition of SQL Server. Chapter 3: Getting familiar with a new server application like SQL Server can be a daunting task for most. There are many different applications installed such as management and development tools, Performance Monitor counters, and many other new things to learn about. This chapter will explore these bits that SQL Server installs. Chapter 4: In this chapter, you get your hands dirty by using the database for its most fundamental purpose: creating tables and storing some data. You’ll also learn to create indexes to help ensure efficient access to that data when you later want to retrieve it. Chapter 5: This chapter covers Transact SQL (T-SQL) syntax. You’ll learn to write and use stored procedures, functions, and triggers, as well as to perform many other common functions within SQL Server.
xx
■ INTRODUCTION
Chapter 6: This chapter gives you a heads-up on how a SQL Server installation is organized. You’ll learn that a SQL Server install includes several databases used by the system in support of those databases that you create for your own use. These databases include the master database containing user logins and the tempdb database used for temporary storage. You’ll also learn about the Windows services that run in the background that make up a running SQL Server installation. Chapter 7: This chapter discusses issues to consider when creating databases such as data and log file placement and the fundamental differences between them. A discussion on database creation wouldn’t be complete without covering storage devices and their effects on databases. Although you probably don’t have your own personal storage area network (SAN) to play with, understanding these types of storage technologies is helpful in understanding how enterprises use SQL Server. This chapter reviews the common storage technologies used with SQL Server. Chapter 8: If you know nothing else as a DBA, you better know how to perform a database backup. This is a core task that almost all DBAs are involved with. This chapter covers the different types of backups and when to use each. Additional topics include special backups such as compressed and encrypted. Chapter 9: Backing up a database is only half the battle. If a disaster occurs, DBAs need to know how to restore the database and get the server back online or restored to a specific point in time. The overall plan for recovering from a disaster is the disaster recovery plan, and this chapter will cover what kind of information this plan should contain as well as how to perform database restores. Chapter 10: Effectively backing up and restoring databases are critical skills for DBAs to possess. However, there are many other functions a DBA performs. Examples of these functions include tuning indexes, creating maintenance scripts, and scheduling jobs. This chapter covers the key tools within SQL Server that help DBAs perform these kinds of tasks. Chapter 11: You as a DBA don’t want to perform every single task yourself, especially the mundane tasks that are the same each day. Automation is a powerful tool that enables you to leverage your time and expertise over a large number of databases. Here you’ll learn to automate the routine work so that you can focus your time and energy on more strategic and interesting tasks. Chapter 12: A very powerful new automation feature introduced in SQL Server 2008 is the maintenance plan. A maintenance plan is an “object” that you create in the database that specifies certain tasks to be performed on a routine basis. Maintenance plans greatly reduce the need to write scripts. Just list the tasks you want to perform and specify dependencies and notification details, and the maintenance plan feature takes care of doing the actual work. Chapter 13: This chapter covers the basic tools used for performance measurement as well as the tools used to tune databases. SQL Server 2008 introduced a few key features in this space including Performance Data Collector. These key improvements will be covered in this chapter. Chapter 14: This chapter covers the SQL Server security model. You’ll learn how users authenticate to SQL Server and are granted access to objects within the server. Chapter 15: DBAs who work for publicly traded companies, health-care companies, or companies that stored and use credit card information will undoubtedly be asked into a few meetings with some auditors. These folks, if they are external to your company, are hired specifically to make sure your company complies with the applicable regulations such as Sarbanes-Oxley, Payment Card Industry (PCI), and others. This chapter describes how SQL Server enables features that help DBAs configure their servers to be compliant.
xxi
■ INTRODUCTION
Chapter 16: This chapter explores how SQL Server is used in the enterprise. It also covers some of the more common applications such as Microsoft System Center Configuration Manager that can be used with SQL Server. Chapter 17: This chapter provides valuable references that will help you as a new DBA continue to build your foundation of knowledge about SQL Server.
Getting the Most from This Book Learning how to manage a database is best done as a hands-on exercise. This book walks through an installation of the evaluation edition of SQL Server. This edition is a free download from http://www.microsoft.com/sqlserver/2008/en/us/trial-software.aspx. The evaluation edition has all the functionality of Enterprise edition and is a great way to start working with SQL Server without any monetary investment. Of course, there are some licensing restrictions with the evaluation edition, such as that you can’t run a production server using it. If you could, Microsoft would be out of a lot of money. To get the most of the book, you should install the product, work through all the examples within each chapter, make your own modifications to the scripts, and see what happens!
Errata Apress makes every effort to ensure that there are no errors in the text or code. However, mistakes happen, and we recognize the need to keep you informed of any mistakes as they’re discovered and corrected. An errata sheet will be made available on the book’s main page at http://www.apress.com. If you find an error that hasn’t already been reported, please let us know.
Contacting the Authors You can contact the book’s lead author, Rob Walters, via his e-mail address at
[email protected].
xxii