Professional Documents
Culture Documents
J. Steven Jones
David W. Tschanz
Dave Owen
Wayne R. Boyer
Credits
EXECUTIVE EDITOR
DIRECTOR OF SALES
EXECUTIVE MARKETING MANAGER
MICROSOFT SENIOR PRODUCT MANAGER
EDITORIAL PROGRAM ASSISTANT
PRODUCTION MANAGER
PRODUCTION EDITOR
CREATIVE DIRECTOR
COVER DESIGNER
TECHNOLOGY AND MEDIA
John Kane
Mitchell Beaton
Chris Ruel
Merrick Van Dongen of Microsoft Learning
Jennifer Lartz
Micheline Frederick
Kerry Weinstein
Harry Nolan
Jim OShea
Tom Kulesa/Wendy Ashenberg
This book was set in Garamond by Aptara, Inc. and printed and bound by Bind Rite Graphics.
The cover was printed by Phoenix Color.
Copyright 2010 by John Wiley & Sons, Inc. All rights reserved. No part of this publication may be reproduced,
stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying,
recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States
Copyright Act, without either the prior written permission of the Publisher, or authorization through payment
of the appropriate per-copy fee to the Copyright Clearance Center, Inc. 222 Rosewood Drive, Danvers, MA
01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, (201) 748-6011,
fax (201) 748-6008. To order books or for customer service, please call 1-800-CALL WILEY (225-5945).
Microsoft, ActiveX, Excel, InfoPath, Microsoft Press, MSDN, OneNote, Outlook, PivotChart, PivotTable,
PowerPoint, SharePoint, SQL Server, Visio, Windows, Windows Mobile, Windows Server, and Windows Vista are
either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries.
Other product and company names mentioned herein may be the trademarks of their respective owners.
The example companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events
depicted herein are fictitious. No association with any real company, organization, product, domain name, e-mail
address, logo, person, place, or event is intended or should be inferred.
The book expresses the authors views and opinions. The information contained in this book is provided without
any express, statutory, or implied warranties. Neither the authors, John Wiley & Sons, Inc., Microsoft Corporation,
nor their resellers or distributors will be held liable for any damages caused or alleged to be caused either directly or
indirectly by this book.
Evaluation copies are provided to qualified academics and professionals for review purposes only, for use in their
courses during the next academic year. These copies are licensed and may not be sold or transferred to a third party.
Upon completion of the review period, please return the evaluation copy to Wiley. Return instructions and a free
of charge return shipping label are available at www.wiley.com/go/returnlabel. Outside of the United States, please
contact your local representative.
ISBN 978-0-470-18365-6
Printed in the United States of America
10 9 8 7 6 5 4 3 2 1
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
| iii
Preface
Welcome to the Microsoft Official Academic Course (MOAC) program for Microsoft SQL
Server Database Design and Optimization. MOAC represents the collaboration between
Microsoft Learning and John Wiley & Sons, Inc. publishing company. Microsoft and Wiley
teamed up to produce a series of textbooks that deliver compelling and innovative teaching
solutions to instructors and superior learning experiences for students. Infused and informed
by in-depth knowledge from the creators of SQL Server, and crafted by a publisher known
worldwide for the pedagogical quality of its products, these textbooks maximize skills transfer
in minimum time. Students are challenged to reach their potential by using their new technical skills as highly productive members of the workforce.
Because this knowledgebase comes directly from Microsoft, architect of the SQL Server
operating system and creator of the Microsoft Certified IT Professional exams (www.microsoft.
com/learning/mcp/mcitp), you are sure to receive the topical coverage that is most relevant to
students personal and professional success. Microsofts direct participation not only assures
you that MOAC textbook content is accurate and current; it also means that students will
receive the best instruction possible to enable their success on certification exams and in the
workplace.
The Microsoft Official Academic Course series is a complete program for instructors and institutions to prepare and deliver great courses on Microsoft software technologies. With MOAC,
we recognize that, because of the rapid pace of change in the technology and curriculum developed
by Microsoft, there is an ongoing set of needs beyond classroom instruction tools for an
instructor to be ready to teach the course. The MOAC program endeavors to provide solutions
for all these needs in a systematic manner in order to ensure a successful and rewarding course
experience for both instructor and studenttechnical and curriculum training for instructor
readiness with new software releases; the software itself for student use at home for building
hands-on skills, assessment, and validation of skill development; and a great set of tools for
delivering instruction in the classroom and lab. All are important to the smooth delivery of an
interesting course on Microsoft software, and all are provided with the MOAC program. We
think about the model below as a gauge for ensuring that we completely support you in your
goal of teaching a great course. As you evaluate your instructional materials options, you may
wish to use the model for comparison purposes with available products.
iv |
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Pedagogical Features
The MOAC textbook for SQL Server Database Design and Optimization is designed to cover
all the learning objectives for that MCITP exam, which is referred to as its objective domain.
The Microsoft Certified Information Technology Professional (MCITP) exam objectives are
highlighted throughout the textbook. Many pedagogical features have been developed specifically for Microsoft Official Academic Course programs.
Presenting the extensive procedural information and technical concepts woven throughout
the textbook raises challenges for the student and instructor alike. The Illustrated Book Tour
that follows provides a guide to the rich features contributing to Microsoft Official Academic
Course programs pedagogical plan. Following is a list of key features in each lesson designed
to prepare students for success on the certification exams and in the workplace:
Each lesson begins with an Lesson Skill Matrix. More than a standard list of learning
objectives, the Domain Matrix correlates each software skill covered in the
lesson to the specific exam objective domain.
A Lab Manual accompanies this textbook package. The Lab Manual contains hands-on
lab work corresponding to each of the lessons within the textbook. Numbered steps
give detailed, step-by-step instructions to help students learn workplace skills associated with database design and optimization. The labs are constructed using
real-world scenarios to mimic the tasks students will see in the workplace.
Illustrations: Screen images provide visual feedback as students work through the
exercises. The images reinforce key concepts, provide visual clues about the steps, and
allow students to check their progress.
Key Terms: Important technical vocabulary is listed at the beginning of the lesson.
When these terms are used later in the lesson, they appear in bold italic type and are
defined. The Glossary contains all of the key terms and their definitions.
Engaging point-of-use Reader aids, located throughout the lessons, tell students why
this topic is relevant (The Bottom Line), provide students with helpful hints (Take Note),
or show alternate ways to accomplish tasks (Another Way). Reader aids also provide
additional relevant or background information that adds value to the lesson.
Certification Ready? features throughout the text signal students where a specific
certification objective is covered. They provide students with a chance to check their
understanding of that particular exam objective and, if necessary, review the section
of the lesson where it is covered.
Knowledge Assessments provide lesson-ending activities.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
| v
Lesson Features
Analyzing and
Designing Security
L ES S O N
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Design Active Directory organizational units (OUs) to implement serverlevel security policies.
Foundational
Foundational
Foundational
Foundational
Modify the security design based on the impact of network security policies.
Foundational
Analyze the risk of attacks to the server environment and specify mitigations.
Foundational
92 | Lesson 4
CERTIFICATION READY?
Be prepared for exam
questions giving you
choices on conflicting
requirements. Pay
attention to stated
objectives and their
importance.
KEY TERMS
audit: An independent verification
of truth.
active directory (AD): The operating systems directory service
that contains references to all
objects on the network. Examples
include printers, fax machines,
user names, user passwords,
Key Terms
Warning!
Warning
Reader Aid
You should make decisions yourself as much as possible; but when youre faced with mandates or directives that conflict with one another, you need to seek resolution from those in
charge of the companyespecially if the decision is made to stray from regulatory guidelines.
Company leaders often have a working relationship with standards bodies or governmental
offices and can adapt the requirements to meet your companys needs.
If youre forced to choose between conflicting requirements yourself, understand the implications of ignoring any particular set of rules. In making your decision, you should meet
all requirements to the greatest extent possible, but understand that governmental regulations usually are more important than corporate or certification ones. Penalties for ignoring
requirements that have been written into law or codified by a governmental office can be
financial woe for your company and may result in incarceration.
If youre choosing between your corporate mandates and the guidelines of a standards body or certification (such as ISO 9000), you should follow your corporate mandates. This is a general guideline; make sure you have the permission of your companys executives to proceed in this manner.
87
Every security decision you make has a cost. It isnt necessarily a monetary cost, such as the
purchase of a piece of auditing software. It can be a cost in terms of time (RSA 2048-bit
encryption takes too long to complete with current technology), in terms of effort (requiring
two-factor authentication will result in too many errors from users), or in terms of another
resource. As the designer for your SQL Server infrastructure, you need to weigh the costs and
benefits of each decision to determine whether its worth pursuing.
Financial costs are simple to determine via price quotes from vendors and suppliers, licensing
costs based on existing installations or user counts, and so on. You can generally gather this
information easily and use it to determine the amount of money that your company must
spend for security items. Make sure to assign these direct dollar costs to each particular item.
Nonfinancial costs are difficult to establish, and youll have to decide how your company will
assign the value of those costs. You need to allocate a value in dollars (or some other currency)
so that you have a method of measuring these expenses along with other costs. You can do this
in a number of ways, almost all of which require that you consult with the people and departments that will be affected to gather information about the impact from a particular decision.
Time is an easy cost to determine. Often, the time an event takes can be translated into an
expense based on the cost of the resources involved. Each employee has a cost that can be
divided out to determine the per-minute value of his or her time. Security decisions often
impose a burden on people that equates to time spent on some activity, so its relatively simple
to determine the security cost of a particular decision.
4 | Lesson 1
ANOTHER WAY
REF
Record SQL Server configuration settings. Record the minimum and maximum memory
settings, the CPUs used by the instance, and the default connection properties for each
SQL Server instance.
Review the configuration management process for proposing, approving, and implementing configuration changes, and identify opportunities to make the process more
efficient. What tools are used?
Assess the quality of the database server documentation.
Verify the capabilities of disk subsystems and physical storage. Determine whether
the RAID levels of existing disk subsystems support data availability and performance
requirements.
Determine the locations of transaction log files and data files.
Examine the use of filegroups.
Are adequate data-file sizes allocated to databases, including the tempdb database?
Verify that the AutoShrink property is set to False, to ensure that the OS files
maintaining table and index data are resized accordingly.
Determine whether disk-maintenance operations, such as defragmentation, are
performed periodically.
Assess Event Viewer errors to identify disk storage-related problems.
TAKE NOTE
LAB EXERCISE
When you examine the cost of time, include all the people involved. For example, a password change resulting from a security decision to expire passwords results in the use of the
time of at least two people: the person deciding whose password must be changed and the
person making the change.
Other costs, such as increased time for customers or clients to use your system, their desire
or ability to work with your system, or even potential costs for others to integrate with you,
must be estimated by someone in your organization. The sales department may need to examine your requirements and determine the opportunity cost of a decision on the companys
overall ability to generate revenue.
In Exercise 4.1, youll determine the time cost of resetting passwords.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
After you gather the requirements from all sources, be sure to document any existing security
settings on your SQL Servers. These may or may not be in conflict with the requirements,
but in designing a security plan, you should consider the current environment. Have
mitigation plans handy for any changes to be sure that the databases remain available and
functional to users.
Before examining how youll use these requirements, you must understand the security scope
in SQL Server.
Youve been assigned the task of architecting a new infrastructure for the SQL Server
2005 upgrade at a U.S. pharmaceutical company. To ensure that your design complies
with all applicable requirements, you schedule interviews with the chief operations officer
and his staff as well as the senior researchers.
Youre informed that you must adhere to a number of requirements: 10CFR15 as mandated
by the U.S. government, Sarbanes-Oxley requirements for the company as a publicly held
entity, and various insurance requirements to ensure worker and customer safety.
The process of complying with these regulations means you must validate every security
decision against all the different requirements. An internal committee of employees will
check your plans compliance when youve completed it.
Once youve made the necessary decisions, you need to ensure that a representative from
each body whose requirements youre meeting audits the plan and documents compliance
with or deviation from each of their requirements.
REF
External Windows
serverlevel security will
be dealt with in Lesson 5
and internal server
instance and database
security in Lesson 6.
In SQL Server, security is applied at various levels, each encompassing a different scope on
which it applies. Security can be applied at the server level, the database level, and the schema
level. This Lesson will examine overall security system design for the entire enterprise.
Figure 4-1 shows the hierarchy of a SQL Server. The highest level is the server instance, which
contains one or more databases. Each database has its own users, which are mapped to server
instance level logins. Database security applies to the database container as well as all objects
within that database. Outside of the SQL Server are the Windows server and enterprise-level
security structures.
SQL Server has a four-part set of security levels: server, database, schema, and object. The
schema level was introduced with SQL Server 2005. A schema is essentially a container of
objects within a database; a single database can include multiple schemas. SQL Server 2000
blended the objects owner and a schema to form a multipart naming system for objects. Thus
dbo. TestTable and Steve. TestTable were two different objects. However, the owner, Steve in
this case, was bound to the objects, and it was cumbersome to remove the user Steve.
126 | Lesson 5
Knowledge Assessment
Case Study
The Ever-Growing Wealth Company
The Ever-Growing Wealth Company manages retirement funds for many people
and is concerned about the security of its data. To ensure that its database servers are
adequately protected, the company decides to review and revamp its security policies.
Planned Changes
The companys management thinks the security policies for its applications must be
strengthened and that encryption needs to be deployed. However, these changes cant
cause problems in the event that disaster-recovery plans must be implemented.
Existing Infrastructure
All these servers are stored in the companys data center, which is a climate-controlled,
converted office in the companys current location. The company would like to move all
its servers to a co-location facility with a dedicated network connection back to the office.
Currently, a tegwc.com domain contains two main organizational units (OU), one for
the internal employees and one for any client accounts.
The two SQL Servers are named instances that use dynamic ports. A firewall protects
the entire network, but all servers exist in a flat Ethernet topology as shown in the Case
Exhibit of this case study.
Business Requirements
The clients of Ever-Growing Wealth expect to be able to access their data at any time
of the day or night. The existing disaster-recovery plan allows system administrators a
five-minute response time to failover the SQL Servers, and this is deemed acceptable.
However, it cant take more time than this to get the application running.
The company expects that regulatory requirements will be enacted soon for all financial
companies, so the strongest encryption possible is preferred, balancing the performance
of the servers. Newer hardware is available to make up for any issues from the implementation of encryption.
Technical Requirements
For the new servers, the company purchased the next generation of hardware to allow
for the additional load of encrypting data. However, complete encryption of all data
using asymmetric keys will likely overload these servers; therefore, the security policy
must work within these hardware constraints.
Each instance has a SQL Server Agent service that performs various functions,
including copying backup files to another server and running business maintenance
jobs that access the mail server.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
88 | Lesson 4
In SQL Server 2000, some key security templates made security cumbersome and resulted
in workarounds that often didnt meet users requirements. As a result, one of the key
design considerations with SQL Server 2005 was an increased level of security for the
server. SQL Server now not only includes more control and capabilities but also makes it
easier for the DBA to administer the security policies for the server.
This Lesson will examine the methods and reasoning behind designing an effective databaselevel security policy for your SQL Server instances.
Before you can develop an effective security policy, you must understand the requirements
that your plan must meet. These include requirements dictated by your business as well
as any regulatory requirements imposed on your business by governmental or regulatory
agencies. Your plan must cover both of these types, and you must resolve any conflicts
between the two based on your situation.
The requirements imposed on your SQL Servers by the business will in all likelihood be easier
to meet (in other words, they will be less restrictive) but will probably be harder to ascertain.
When someone in business decides on a requirement for an application, that requirement
may or may not be documented thoroughly, which can cause you difficulties during planning.
Youll spend much of this part of the design process interviewing executives, business liaisons,
stakeholders in each application, developers, administrators, and anyone else who may know
why an application has a security need.
TAKE NOTE
Warning!
If SQLProd01 fails for some reason, SQLProd02 will become the primary server after failover
and start responding to client requests. Only one servers resources are used at a time, meaning that half your server hardware (excluding disk drives) isnt being used at any given time.
In this case, only one SQL Server license is needed for the one virtual server.
A second example, illustrated in Figure 10-2, shows a three-node, active/active cluster with three
physical servers and three virtual servers. In this case, each server is actively used at all times to
do work, and three SQL Server licenses are required for the three active server instances.
As you gather this information, document it carefully. You may want to segregate the
data by server instance and database for ease of locating it later. Youll use the various
requirements to design the security policy for your SQL Server.
The failover strategy is more complex in this example, with each server having a designated
failover server in a round-robin fashion. Table 10-2 shows the virtual servers, primary physical
instance, and the failover physical instance.
Figure 10-2
Three-node active/passive
clustering
Client
Informative
Diagrams
SQLProdA
SQLProd02
SQLProd01
Shared Disk
SQLProdC
SQLProdB
Client
Client
SQLProd03
Table 10-2
Easy-to-Read
Tables
Three-node failover
V IRTUAL S ERVER
P RIMARY S ERVER
S ECONDARY S ERVER
SQLProdA
SQLProd01
SQLProd02
SQLProdB
SQLProd02
SQLProd03
SQLProdC
SQLProd03
SQLProd01
If any node fails, then the virtual server moves to another instance. However, when this
occurs, one physical server will be spreading its resources to serve two virtual instances. In
this example, if SQLProd02 fails, then SQLProd03 must serve clients connecting to both
SQLProdC and SQLProdB.
In order for the applications to function at a similar performance level, each server must have
enough spare processor cycles and memory to handle the additional load of a second instance
in the event of a failover.
CERTIFICATION READY?
When examining
security, be sure you
grasp the breadth and
depth of this topic. Do
you understand how
authentications, physical
barriers, firewalls,
disaster recovery plans,
business recovery plans,
risk analyses, policies,
enforcement, incident
response plans, and
forensic investigations all
interact?
Every server that you have running in your enterprise should be physically secured from
unauthorized access. There are many ways of enforcing security and protecting your
server through software, but most of these can be circumvented if the server can be
physically accessed or attacked. The local file system security can be bypassed if someone
can boot a server from another source, and this can lead to security-related files or data
files being copied and the data compromised.
SQL Servers are no exception. But because they can be easily set up on many platforms and
are used in testing new solutions, sometimes the servers physical security isnt maintained as
theyre moved to an employees office or cubicle.
If youre storing enterprise data on a SQL Server, the server should be stored in a physically
secure manner. This means behind a locked door with a limited number of people able to
access the machine. Access controls that log and control which individuals can access the
room are preferred; theyre even mandated in some environments.
SQL Servers often have large disk subsystems, so be sure the disks are secured to prevent their
physical theft. Due to the large data sets, tape backup systems are often used. Make sure physical control over these tapes is maintained and they arent allowed to sit on a desk or other
unsecured area where unauthorized people have access to them.
S K I L L S U M M A RY
This Lesson has investigated how to design Windows server-level security. The server-level
policies provide the highest level of security for SQL Server. Your password and encryption
policies should provide the level of security you need, balanced with the performance required
on your server. The services, service account, and firewall policies should be set to the
absolute minimums required for each server. Enabling all services or opening all possible ports
increases the surface area available for attack on your server unnecessarily. Configure and
make available those items only when you need them, and disable them when theyre no
longer needed.
Security is an ongoing process and should evolve as your server changes. Developing policies
and procedures that make the least amount of resources available from a security perspective
will help to ensure that youre protected and that your server functions in an optimum
manner at all times.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
156 | Lesson 7
Steve then grants Dean permission to execute this stored procedure. When Dean executes it, permissions are checked to be sure he can execute the module, but the permissions check on Steve.MyTable uses Steves permission set.
EXECUTE AS OWNER. This context uses the permission set of the module owner for
all objects referenced in the module. If the module doesnt have an owner, the owner of
the modules schema is used instead.
This is similar to EXECUTE AS SELF if the person creating the module is the same as
the owner at execution time. However, because object ownership can be changed, this
context allows the permission check to move to the new owner of the object.
CERTIFICATION READY?
Know the forms of the
EXECUTE AS command
and be prepared to
identify how the use of
this command would
alter the execution
context.
TAKE NOTE
In the three cases where execution context is set to a particular username, that user cant be
dropped until the execution context is changed.
Because users tend to change more often than permissions or objects, you use techniques that allow for this flexibility. In assigning permissions, you use groups and roles
to collect users together for easy administration. Starting with the 2005 version of SQL
Server the concept of a schema has been available. The schema separates object ownership from individual users for the same reason. And this should caution you against
using a particular user or SELF to change execution context: Because a one-to-one
mapping exists between the user and a module, if the user needs to be dropped, every
module must be altered to change the execution context. This is the same administrative
issue with users both owning an object and being its schema.
Knowledge Assessment
206 | Lesson 9
If you think your environment is static enough to use individual users, then EXECUTE
AS is a good way to change permissions in only one module.
Knowledge Assessment
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
1. Which of the following are benefits of having database naming conventions? (Choose all
that apply. )
a. Provides a method to organize infrastructure
b. Reduces the learning curve for new database administrators
c. Makes coding easier
d. All of the above
2. Which of the following are the most important attributes of a naming convention?
(Choose all that apply.)
a. Flexibility
b. Regulatory requirements
c. Consistency
d. Size of the organization
Manage services. You can use Configuration Manager to start, pause, resume, or stop services, to view service properties, or to change service properties. As you can see in Figure 2-3,
Configuration Manager gives you easy access to SQL Server Services.
3. Which of the following database objects should have a naming convention? (Choose all
that apply.)
a. Database
b. Table
c. Trigger
d. Index
Change the accounts used by services. You should always use SQL Server tools, such
as SQL Server Configuration Manager, to change the account used by the SQL Server or
SQL Server Agent services, or to change the password for the account. You can also use
Configuration Manager to set permissions in the Windows Registry so that the new account
can read the SQL Server settings.
Manage server network and client protocols. SQL Server 2005 supports Shared Memory,
TCP/IP, Named Pipes, and VIA protocols. You can use Configuration Manager to configure server and client network protocols and connectivity options. After the correct protocols
are enabled using the Surface Area Configuration tool, you usually dont need to change the
server network connections. However, you can use SQL Server Configuration Manager if you
need to reconfigure the server connections so that SQL Server listens on a particular network
protocol, port, or pipe.
5. Which of the following are good naming practices for indexes? (Choose all that apply.)
a. Combine the name of the table and the names of the columns.
b. Specify whether the index is clustered or nonclustered.
c. Include a prefix such as IX_.
d. Use spaces to separate key elements.
6. When you have an existing database with poorly named objects that cannot be renamed,
what is the best way improve clarity of the naming conventions?
a. Use a lookup table.
b. Create a new column.
c. Note in your standards documentation what the poorly named object actually
represents.
d. Use a synonym.
Assign TCP ports to instances. If instances must listen through TCP ports, you should
explicitly assign private port numbers. Otherwise, the port numbers are dynamically assigned.
You can use the SQL Server Configuration Manager to assign port numbers. Although you
can change port numbers that are dynamically assigned, client applications that are set up to
use these port numbers may be adversely affected.
TAKE NOTE
When youre assigning ports, make sure they dont conflict with port numbers that are
already reserved by software vendors. To determine which port numbers are available,
visit the Internet Assigned Numbers Authority (IANA) Web site at the following URL:
www.iana.org/assignments/port-numbers.
8. Which of the following are not recommended names for tables in a SQL Server
database? (Choose all that apply.)
a. Person.Address
b. Person.Address Type
c. tbl_Person.AddressType
d. dbo.MSmerge_history
Figure 2-3
SQL Server Configuration
Manager is the preferred tool
to manage many aspects of
SQL Server instance configurations, including services.
Screen Images
LAB EXERCISE
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
C ONVENTION
M EANING
CERTIFICATION READY?
TAKE NOTE
ANOTHER WAY
REF
Click OK.
LAB EXERCISE
x |
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
The Microsoft Official Academic Course programs are accompanied by a rich array of resources
that incorporate the extensive textbook visuals to form a pedagogically cohesive package.
These resources provide all the materials instructors need to deploy and deliver their courses.
Resources available online for download include:
The MSDN Academic Alliance is designed to provide the easiest and most inexpensive
developer tools, products, and technologies available to faculty and students in labs,
classrooms, and on student PCs. A free 3-year membership is available to qualified
MOAC adopters.
Note: Microsoft SQL Server can be downloaded from MSDN AA for use by students in
this course
The Instructors Guide contains Solutions to all the textbook exercises as well as chapter
summaries and lecture notes. The Instructors Guide and Syllabi for various term lengths
are available from the Book Companion site (www.wiley.com/college/microsoft).
The Test Bank contains hundreds of questions in multiple-choice, true-false, short answer,
and essay formats and is available to download from the Instructors Book Companion site
(www.wiley.com/college/microsoft). A complete answer key is provided.
PowerPoint Presentations and Images. A complete set of PowerPoint presentations is
available on the Instructors Book Companion site (www.wiley.com/college/microsoft) to
enhance classroom presentations. Tailored to the texts topical coverage and Skills Matrix,
these presentations are designed to convey key Microsoft SQL Server concepts addressed
in the text.
All figures from the text are on the Instructors Book Companion site (www.wiley.com/
college/microsoft). You can incorporate them into your PowerPoint presentations, or create
your own overhead transparencies and handouts.
By using these visuals in class discussions, you can help focus students attention on key
elements of Windows Server and help them understand how to use it effectively in the
workplace.
When it comes to improving the classroom experience, there is no better source of ideas
and inspiration than your fellow colleagues. The Wiley Faculty Network connects teachers
with technology, facilitates the exchange of best practices, and helps to enhance instructional
efficiency and effectiveness. Faculty Network activities include technology training and
tutorials, virtual seminars, peer-to-peer exchanges of experiences and ideas, personal
consulting, and sharing of resources. For details visit www.WhereFacultyConnect.com.
Microsoft SQL Server Books Online. This set of online documentation helps you understand SQL Server and how to implement data management and business intelligence projects.
SQL Server Books Online is referred to throughout this text as a valuable supplement to your
work with SQL Server. You can find SQL Server Books Online at http://msdn.microsoft.
com/en-us/library/ms130214(SQL.90).aspx and http://msdn.microsoft.com/en-us/library/
ms130214.aspx.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
| xi
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
| xiii
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
of computers available at the testing center, the number of other testers who have already been
scheduled for the day on which you want to take the test, and the number of times per week
that the testing center offers MCITP testing. In general, you should call to schedule your test at
least two weeks prior to the date on which you want to take the test.
When you arrive at the testing center, you might be asked for proof of identity. A drivers
license or passport is an acceptable form of identification. If you do not have either of these
items of documentation, call your testing center and ask what alternative forms of identification will be accepted. If you are retaking a test, bring your MCITP identification number,
which will have been given to you when you previously took the test. If you have not prepaid
or if your organization has not already arranged to make payment for you, you will need to
pay the test-taking fee when you arrive.
Student CD
The CD-ROM included with this book contains practice exams that will help you hone
your knowledge before you take the MCITP Microsoft SQL Server Database Administrator
70443/450 certification examination. The exams are meant to provide practice for your
certification exam and are also good reinforcement of the material covered in the course.
The enclosed Student CD will run automatically. Upon accepting the license agreement, you
will proceed directly to the exams. The exams also can be accessed through the Assets folder
located within the CD files.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Dave Owen graduated from California State Polytechnic College as an Electronic Engineer
with an emphasis on communications theory. He did, however, have to take a programming
course: Fortran 4 with data entry on a punch card machine and submitted as a batch file for
overnight processing.
He was the seventh employee hired in 1971 at the Naval Civil Engineering Laboratory for
the then brand new initiative to bring naval facilities in line with environmental compliance
regulations. He ended up as the data management guy. He was a programmer (it was Rocky
Mountain BASIC then); he was the network guy; he was the database guy (you have probably never heard of Speed for the Wang Computer System); he was the enterprise planner (he
led an effort to update the Navys data tracking system, which was approved and budgeted
at $33 million); he ran the help desk (his team was the only Naval Facilities Engineering
Command group to receive an Outstanding rating by the Inspector General); he was having
a good time.
After retirement, he visited the County of Ventura Workforce Development Division who
offered him training to become certified in Microsoft and Novell technologies. He was too
long entrenched. He needed to become current. He became a CNA, MCSE, and MCDBA.
In the fall of 1998 he started teaching at Moorpark College. He taught every certificated
computer and networking topic desired by the Department Chair and earned his MCT
two years later. In addition he started teaching at Microsoft Certified Partners for Learning
Solutions such as New Horizons. A lot of other certifications followed.
He likes teaching. He learns more from students than self study or trying to fix problems.
Students approach situations in ways he can never imagine. Understanding their perspective
provides him with infinitely more insight than he could ever glean alone. Now hes preparing
college text books and other publications.
Wayne Boyer is a consultant, systems analyst, programmer, network engineer, and information systems manager who started working with relational database systems just a short
while ago in 1978. Wayne has extensive application systems experience with manufacturing
and financial systems sometimes commonly referred to as MRP and ERP systems. Most of
Waynes experience in years past was with HP-3000 minicomputer systems running a relational database system known as Image. This experience with database systems let to Waynes
current expertise and experience with modern relational database systems such as SQL Server
and Oracle. With over 30 years of Information Technology experience, Wayne brings a depth
of real-world experience to current technology topics. Currently Wayne is teaching Microsoft
curriculum topics at Moorpark College while also consulting and providing support for a
wide variety of clients on a range of IT related subjects. He has also acquired a number of
industry certifications: MCSE, MCDBA, MCITP for SQL Server 2005, and MCITP for
Enterprise Support. Currently Wayne is working toward Cisco networking certification as
well as an upgrade to MCITP for SQL Server 2008.
xvi |
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Steve Jones has been working with SQL Server for more than a decade, starting with v4.2 on
OS/2 and enjoying the new features and capabilities of every version since. After working as a
DBA and developer for a variety of companies, Steve founded SQLServerCentral.com along
with Brian Knight and Andy Warren in 2001. SQLServerCentral.com has grown into a wonderful SQL Server community that provides daily articles and questions on all aspects of SQL
Server to over 300,000 members. Starting in 2004, Steve became the full-time editor of the
community and ensures it continues to evolve into the best resource possible for SQL Server
professionals. Over the last decade, Steve has written more than 200 articles about SQL
Server for SQLServerCentral.com, the SQL Server Standard magazine, SQL Server Magazine,
and Database Journal. Steve has spoken at the PASS Summits where SQLServerCentral.com
sponsors an opening reception every year as well as written a prior book for Sybex on SQL
Server 2000.
David W. Tschanz is the coauthor of the recent Sybex book Mastering SQL Server 2005. He
has been working with and managing large datasets for four decades. His work has included
analysis of population dynamics, voting behavior, and epidemiological data. He has been
writing on computer topics for the past several years, including 4 books and about 100
articles in the area. He is also a regular contributor to Redmond magazine. Dave currently lives
outside the United States, where his eclectic nature allows him to pursue projects involving
databases, IT infrastructure, web development, archaeology, the ancient Nabataean capital
of Petra, medical history, military science, and demography. He can be reached by e-mail at
desertwriter1121@yahoo.com, or look for him in Connecticut, Saudi Arabia, or Tasmania, his
three favorite haunts.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Acknowledgments
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Acknowledgments | xix
Before embarking on a career in education, Penny worked in the fields of advertising, marketing/sales, mechanical and electronic engineering technology, and computer programming. When
not working from her home office or indulging her passion for lifelong learning, Penny likes to
read mysteries, garden, and relax at home in Hamilton, Ontario, with her Shih-Tzu, Gracie.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
xx | Acknowledgments
We thank Steve Strom from Butler Community College for his diligent review, providing
invaluable feedback in the service of quality instructional materials.
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Acknowledgments | xxi
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
xxii | Acknowledgments
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Acknowledgments | xxiii
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Brief Contents
Preface
1
2
iv
30
150
168
9
10
11
12
Glossary
Index
209
242
265
285
287
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
| xxv
Contents
Thinking Holistically 3
Assessing the Current Configuration 3
Accommodating Changing Capacity Requirements
Skill Summary 25
Knowledge Assessment
Case Study 28
26
Skill Summary 54
Knowledge Assessment
Case Study 55
55
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
| xxvii
xxviii | Contents
Forming a Team 59
Making the Decision to Consolidate 60
Developing Guidelines for the Consolidation
Project 65
Examining Your Environment 66
Phase 2: Planning 73
Evaluating Your Data 74
Making Initial Decisions about the Plan 75
Case Study: Consolidating and Clustering 77
Planning to Migrate Applications 78
Case Study: Avoiding Scope Creep 79
Phase 3: Developing 80
Acquiring Your Hardware 80
Creating the Proof of Concept 81
Creating the Pilot 81
Phase 4: Deploying 82
Skill Summary 83
Knowledge Assessment 83
Case Study 83
107
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
Contents | xxix
160
Skill Summary
164
Knowledge Assessment
Case Study 165
165
190
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
xxx | Contents
200
206
215
236
237
238
265
267
274
www.wiley.com/college/microsoft or
call the MOAC Toll-Free Number: 1+(888) 764-7001 (U.S. & Canada only)
271
Designing the
Hardware and
Software Infrastructure
L ESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
budgetary constraint: Limits
placed on your ability to invest
as much as you might wish in an
infrastructure improvement project.
capacity: A measure of the
ability to store, manipulate, and
report information collected for
the enterprise. Excess capacity
suggests a declining business
need or too much investment
in infrastructure.
2 | Lesson 1
There is an old saying among carpenters and woodworkers when preparing to work with
a good or particularly special piece of hardwood: Measure it twice, and cut it once. In
other words, make sure of what youre doing and then get it right the first time, because it
might be the only chance you have.
Added to that old saying are others: No one plans to fail, they fail to plan; Failure to plan
on your part does not constitute an emergency on mine; and A house built on sand will fall
down. The point is to emphasize the role that careful planning and design of the underlying
support structure, the infrastructure, plays in the successful completion of any projectfrom a
childs dollhouse to a family vacation to a career as a database administrator.
If you were going to build a house, either for yourself or someone else, the first thing youd
want to know is how it will be used and how big it needs to be. To find out, youd ask yourself (or a client) some key questions: How much land is available on which to build? How
many people will live there? Does the couple have plans for additional children? Will it be
only a house, or will it serve as a home office? Is a separate section with a separate entrance
required? How much money and resources are available? With that information, youd then
design and build accordingly. When it comes to a database server infrastructure, you need to
do the same.
To reemphasize: Its very important that you grasp the underlying premise of this lesson and the
rest of the book. If you understand how to plan and design a database infrastructure and how to
successfully implement those plans, you will reap enormous benefits in terms of time saved and
resources properly allocated while increasing the probability that your activities will succeed.
The process of designing infrastructure often depends more on your understanding of the
underlying premises than on a single set of rules. Every infrastructure you design or work on
will need to meet unique requirementsthere is no one size fits all. Unless you understand
the hows and whys of your process, the end result will be far from satisfactory.
In this lesson, youll take the first steps toward designing a database server infrastructure. Like
anything you build, whether a birdhouse or the Great Pyramid, the foundation is the key. First
you must review strategies for assessing your current configuration and gathering data about the
current capacity of key resources such as storage, CPU, memory, and network bandwidth. You
then have to cover how to use this data, along with the business requirements of the organization, to estimate future capacity needs. The second part of the lesson will look at how to specify
software versions and hardware configurations for use in the organizations requirements.
You must first understandcompletelythat which existsthe as-is. The second step
involves understanding what is desiredthe to be. And finally, you must understand the
plans for bridging the gapthe implementation strategy.
As you almost certainly know, youll rarely, if ever, be involved in designing a completely
new database server infrastructure. Youll nearly always be working with an organization that
has an existing infrastructure that needs to change to meet enterprise growth and to enhance
performance.
In that case, the first step is not to reach for a piece of paper to draw your dream infrastructure.
Instead, the first step is to evaluate the various subsystems of the existing infrastructure and
figure out what you have to work with. This initial evaluation process will aid you in assessing
how well the different subsystems interact and will also highlight potential trouble spots.
Next, you should gather the requirements you need to have in place for the modified
infrastructure. These requirements may be technical or business related (theyre usually both),
and they need to be prioritized in that context. Once youve established the requirements, set the
priorities, and determined the funding levels, you can design modifications to the infrastructure.
TAKE NOTE
When designing modifications, a good practice is to standardize the hardware and software
configuration of database servers as much as possible. Doing so simplifies the design of the
infrastructure and reduces the maintenance overhead. In addition, standardization results
in significant cost savings.
Thinking Holistically
Whether before or after youve analyzed the capacity needs of the enterprises individual
database servers, you must at some pointthe earlier the betterevaluate the existing
database server infrastructure as a whole. This view can give you a quick assessment of the
overall health of the infrastructure and help you determine any recurring trouble spots.
You should also think in terms of the ideal. Are the databases optimally designed? Are
disk-storage systems being used effectively? Are CPU and memory types and allocations
appropriate? Is the network properly designed and prepared for the new infrastructure?
You should use your evaluations to determine what modifications should be made to the
infrastructure to support business growth. And you should be able to make the business case
for your recommendations.
Download
REF
4 | Lesson 1
ANOTHER WAY
REF
Record SQL Server configuration settings. Record the minimum and maximum memory
settings, the CPUs used by the instance, and the default connection properties for each
SQL Server instance.
Review the configuration management process for proposing, approving, and implementing configuration changes, and identify opportunities to make the process more
efficient. What tools are used?
Assess the quality of the database server documentation.
Verify the capabilities of disk subsystems and physical storage. Determine whether
the RAID levels of existing disk subsystems support data availability and performance
requirements.
Determine the locations of transaction log files and data files.
Examine the use of filegroups.
Are adequate data-file sizes allocated to databases, including the tempdb database?
Verify that the AutoShrink property is set to False, to ensure that the OS files
maintaining table and index data are resized accordingly.
Determine whether disk-maintenance operations, such as defragmentation, are
performed periodically.
Assess Event Viewer errors to identify disk storage-related problems.
REF
REF
REF
6 | Lesson 1
This may include placing mission-critical data on a redundant site that can be used as an
emergency backup during infrastructure changes.
Now that youve examined some infrastructure-wide and general considerations for assessing,
planning, and modifying a database server infrastructure, you need to look at the process in
more detail, especially as it relates to specific capacity requirements.
Your design must meet current and projected data storage requirements. You also must
decide on a horizon when anticipating changes. You can anticipate near-term changes far
better than long-term requirements. Make everyone aware of your forecasting periods.
There are two sources of capacity requirements: the business and technical requirements of
the organization. The technical requirements are dictated by need and availability. You should
also determine the business goals of the organization for which youre developing the database
infrastructure. Without knowing those, you cant analyze or forecast its capacity needs, any
more than you can build the best possible house without knowing what it will be used for.
With those two points in mind, you have two other key tasks to perform: assessing the current capacity of system resources; and identifying any information, such as growth trends,
that you can use to forecast future needs. Most of the time, you can correlate the trends with
a variable that can be measured, such as the database transaction growth rate (the rate at
which the read/write activity on the database server grows.)
In the following sections, youll learn how to gather data about the current capacity of key
system resources such as storage, CPU, memory, and network bandwidth. Then, youll learn
how to use the data to estimate future capacity needs, using that information to design
(or redesign when one exists) a database infrastructure.
LAB EXERCISE
If youre examining an existing system, make sure you base your measurement of the
current disk usage on a properly sized database and that adequate disk space is already
allocated for data and log files. If adequate disk space is allocated for these files, SQL
Server doesnt need to dynamically grow the database and request extra disk space from
the operating system. The process of allocating extra disk space for a file uses significant
disk resources. In addition, the process can cause physical file fragmentation because disk
segments are added to an existing file.
Disk throughput capacity. Next, assess the disk I/O rate that the database requires. You
can use System Monitors PhysicalDisk:Disk Read Bytes/sec and the PhysicalDisk:Disk
Write Bytes/sec counters to measure disk I/O. If the database receives mostly reads, also
check the Avg. Disk Read Queue Length counter value, which should be low for optimal performance. If the database primarily receives writes, check the Avg. Disk Write
Queue Length counter value, which should also be low.
Locations and roles of database servers. When youre working with a distributed environment, you should establish where the database servers are (and should be) and their
different roles, because that may require a different disk-capacity assessment for each site
and each server. For example, the servers at an organizations branch offices may store
only a subset of the data that is stored on the main server at headquarters. Based on the
roles of the servers, you may be able to identify which databases are most likely to experience growth in disk-space usage or have particularly high or low disk-space requirements.
In Exercise 1.1, youll learn how to use System Monitor to assess current disk throughput.
8 | Lesson 1
You can make an estimate of future trends using any of a number of formulas where
F
C
T
A
R
Linear growth: If you expect disk space to grow by a constant amount in a specific period,
the growth is linear. In that case, you can apply the following formula:
F C (A T)
For example, if you have an 800 GB database thats expected to grow 100 GB per year, in
four years the database is expected to be 1200 GB: 800 GB (100 GB 4) 1200 GB
Compound growth: If you expect disk space to grow at a constant rate during a specific
period (for example, at a certain percentage per month or per quarter), that growth is
described as compound. In that instance, use the following formula:
F C (1 R)^T
For example, if an 800 GB database is expected to grow by 3 percent per quarter for two
years, the resulting additional disk space required in eight quarters (two years) will be
1013 GB: 800 (1 .03)^8 1013 GB. The total database size would be 1813 GB:
800 GB 1013 GB 1813 GB.
TAKE NOTE
In this type of formula, you should express the growth rate as a decimal translation of the
percentage value. For example, if the growth rate is 3 percent per quarter, use the value
0.03 in the formula. In this example, the number of periods is specified in quarters so that
its consistent with the growth-rate unit.
Geometric growth: If the disk space is expected to grow periodically by some increment,
but the increment itself is also growing at a constant rate, the disk space requirement grows
geometrically. In this case, use the sum of a series formula (also called a geometric series) to
determine the projected size:
F C ((Initial Increment) (1 Increment Growth Rate)^(T 1))) / (1 R))
LAB EXERCISE
For example, if a 1000 GB database grows by an increment that starts at 3 GB per month
and increases at 2 percent per month, then in 24 months the total disk space required will
grow to 1096 GB: 1000 (3 (1 1.02^(24 1))) / (1 1.02) 1096 GB.
In Exercise 1.2, youll try your hand at forecasting future disk-storage requirements.
perfect condition, a functional tape drive of the correct type would be needed in order
to read these tapes.
Privacy/Security. Regulations, industry guidelines, or legislation may mandate that
security measures, including encryption, be undertaken to protect consumer data. For
example, health insurers may be required to ensure the privacy of data. Such regulations
affect the data distribution strategy and, consequently, the disk-space capacity of local
and remote servers.
Privacy-related regulations may require data to be stored in an encrypted format. In SQL
Server, you can store data in an encrypted format by using several encryption algorithms.
However, encrypted data requires more disk space than nonencrypted data. In addition,
encryption increases CPU usage.
LAB EXERCISE
In Exercise 1.3, youll use SQL Server Configuration Manager to gather information about
database servers.
10 | Lesson 1
Analyze the traffic between servers and between clients and servers. Then, use the data you
gather to identify potential bottlenecks. Key areas to review include:
TAKE NOTE
Traffic between servers. Use System Monitor counters to analyze the traffic caused by
backup processes, database mirroring, and replication:
Backup processes. The SQLServer: Backup Device:Device Throughput Bytes/sec
counter specifies the number of bytes per second that the backup device currently
supports. You should also review the backup strategy. If the amount of data is large and
available network bandwidth is low, frequent backups to network devices can saturate
the network.
Database mirroring. The SQLServer:Database Mirroring:Bytes Sent/sec and Bytes
Received/sec counters indicate the number of bytes transferred from the principal
server to the mirror server.
Replication. No single set of counters in System Monitor helps you analyze all
replication traffic; hence, what you need to use will depend on the type of replication
being used. In the case of subscribers, for example, you can monitor commands
delivered per second or transactions received per second.
Traffic between clients and servers. Among other things, you must determine the
client traffic on the network, assess how well the current network supports the user
load, and identify the additional traffic that will be caused by an increase in user load
or changes in the application. A useful technique is to use the System Monitor counter
Network Interface: Bytes Totals/sec counter to establish the number of bytes transferred
across the database servers network interface. You need to do this for each network
interface on the server. Check for a correlation exists between the Network Interface:
Bytes Total/sec counter and the SQLServer:General Statistics:User connection counter.
By doing this, you can determine the network traffic caused by users.
Potential bottlenecks. Running Network Monitor on the database server lets you determine the number of bytes used, the percentage of the total bandwidth used, and the
number of bytes transmitted in a specific period. You can also filter specific patterns and
protocols for a more granular approach. Analyze this data to identify bottlenecks, and
work with the network administrator on strategies to eliminate the bottlenecks.
Youll review considerations for choosing a CPU, such as the performance-versus-cost benefit
of using processors with 32-bit and 64-bit architectures, and of using processors with multicore and hyperthreading technologies, later in this lesson.
TAKE NOTE
Dynamic affinity is
tightly constrained by
per-CPU licensing.
When you set the
affinity mask, SQL
Server verifies that the
settings dont violate the
licensing policy.
Type of CPUs. Identify the database servers in the system. For each, make a list of
its current CPU, speed, architecture (32-bit or 64-bit), and whether the processor is
multicore or capable of hyperthreading.
Affinity mask settings. By default, each thread allocated by a SQL Server instance is
scheduled to use the next available CPU. However, you can set the affinity mask to restrict
an instance to a specific subset of CPUs. Additionally, setting the affinity mask ensures that
each thread always uses the same CPU between interrupts. This reduces the swapping of a
thread among multiple CPUs and increases the cache-hit ratio on the second-level cache.
Current CPU usage. To identify any CPU performance issues, you should set a baseline of CPU usage in the current environment. To do so, first collect basic operations
data, such as the number of user connections and the amount of application data. Next,
establish the current CPU usage using monitoring tools such as System Monitor. Finally,
correlate the operations data with the CPU usage.
Hardware bottlenecks, recompilation of stored procedures, and the use of cursors
are some of the main causes of a decrease in CPU performance. To identify CPU
performance problems, use the counters that are included in System Monitors
SQLServer: Plan Cache and SQLServer:SQL Statistics objects.
TAKE NOTE
Some operating system licenses restrict the number of CPUs that may be used. Planning to
use more CPUs must take any such limitations into account.
12 | Lesson 1
TAKE NOTE
When youre trying to establish actual memory usage and peak usage, make sure you
collect information over a complete business cycle in order to obtain the most accurate
data. For example, if an organization generates a large number of reports the first week
of each month, collect the peak usage data when those reports are generated.
LAB EXERCISE
TAKE NOTE
Microsoft has
replaced the Microsoft
Operations Manager
(MOM) product
with System Center
Operations Manager
(SCOM).
Determine whether the current database and memory size match is correct. If the
database, including its indexes, fits completely into the available memory, there will be no
page faults. When a large database cant fit in memory, some data must be retrieved from
the disk when required. Page faults can be minimized by using the buffer cache efficiently.
Determine the amount of memory being used by SQL Server connections.
In Exercise 1.4, youll use System Monitor to assess memory requirements.
The point of all this collecting and reviewing is to identify trouble spots that need to be
addressed in the current configuration or that will play a role in modification and future
growth of the infrastructure.
Consequently, you should track memory usage values regularly and establish a baseline. To
gather data for establishing the baseline, you can use the System Monitor counters for SQL
Server memory usage. When theyre present, you can also use management tools such as
Microsofts System Center Operations Manager (SCOM) to gather data on memory usage
across a set of enterprise database servers.
You should also establish minimum and maximum usage values. Using this data ensures that
the memory usage for the current period doesnt exceed the established limits. If you compare
current memory usage values with the baseline, you can assess whether SQL Server has sufficient memory for normal operations. If memory is insufficient, the database server is said to
be under memory pressure, a circumstance that needs to be addressed sooner rather than later.
Microsoft employs lots of programmers working diligently to change operating systems and
applications. Intel, AMD, and Nvidia work long hours to make improvements. Knowledge
changes. Truth is time dependent. Your challenge is to keep up. This is no mean feat.
In this section of the lesson, you wont learn every single aspect of hardware and software
selection that you should apply. Given the rate of hardware and software change, any specific
recommendations would likely be out of date by the time this textbook reaches the shelves.
14 | Lesson 1
However, youre going to need to make these decisions every step of the way. There are no
hard-and-fast rules, but there are best practices. Apply them, and you cant go wrong.
TAKE NOTE
E DITION
AND
EDITION
16 | Lesson 1
Table 1-2
SQL Server 2008 editions and minimum operating system versions and editions
E DITION
AND
EDITION
E DITION
SQL 2008 Developer (64-bit) IA64
AND
EDITION
18 | Lesson 1
Table 1-2
SQL Server 2008 editions and minimum operating system versions and editions (Continued )
E DITION
AND
EDITION
E DITION
AND
EDITION
(Continued )
20 | Lesson 1
Table 1-2
SQL Server 2008 editions and minimum operating system versions and editions (Continued )
E DITION
CERTIFICATION READY?
Know the different
editions and their
requirements and
limitations.
TAKE NOTE
AND
EDITION
Both SQL Server 2005 and SQL Server 2008 have a specialized edition for embedded
applications (such as handheld devices). This embedded edition is the Compact edition
and because of its very specialized nature, we will not discuss it further in this text.
22 | Lesson 1
on a single physical core. Each state acts as a logical CPU for the operating system. However,
the two logical CPUs use the same execution resources, so you dont get the performance benefits of using two physical CPUs.
In the recent past 64-bit, multicore, and hyperthreading CPUs were more expensive than 32-bit
CPUs. SQL Server 2005 requires a variety of different CPUs depending on edition, as summarized
in Table 1-3. Table 1-4 summarizes the same information for the editions of SQL Server 2008.
Table 1-3
SQL Server 2005 editions and
minimum CPU type and speed
E DITION
OS T YPE
Enterprise, Standard,
and Developer
64-bit
Enterprise, Standard,
and Developer
IA64
Enterprise, Standard,
Workgroup, Developer,
and Express
32-bit
AND
S PEED
Table 1-4
SQL Server 2008 editions and
minimum CPU type and speed
E DITION
OS T YPE
M INIMUM CPU
T YPE AND S PEED
R ECOMMENDED
CPU S PEED
Enterprise, Standard,
Developer, Workgroup,
Web, and Express
64-bit
Enterprise
IA64
Developer
IA64
Not specified
Enterprise, Standard,
Developer, Workgroup,
Web, and Express
32-bit
E DITION
OS T YPE
M INIMUM RAM
R ECOMMENDED RAM
Enterprise, Standard,
Workgroup, and Developer
32-bit, 64-bit
and Itanium
512 MB
1 GB or more
Express
32-bit
192 MB
512 MB or more
24 | Lesson 1
Table 1-6
SQL Server 2008 editions and
minimum RAM
E DITION
OS T YPE
M INIMUM RAM
R ECOMMENDED RAM
Enterprise, Standard,
Developer, Workgroup,
and Web
64-bit
512 MB
2 GB
Express
64-bit
512 MB
1 GB
Enterprise and
Developer
IA64
512 MB
2 GB
Enterprise, Standard,
Developer, Workgroup,
and Web
32-bit
512 MB
2 GB
Express
32-bit
256 MB
1 GB
Microsoft has published disk space requirements for installable software modules within SQL
Server 2008. These are the space requirements:
Database Engine, Replication, Full-Text Search
Analysis Services
Reporting Services
Integration Services
Client Services
Books Online
280 MB
90 MB
120 MB
120 MB
850 MB
240 MB
To determine SQL Server 2008 disk space requirements, first determine the modules to be
installed and then add up the requirements for those modules.
Once the hardware and the operating system have been selected to allow for dynamic
hardware changes, then the edition of SQL Server to be used can be selected. Support for
additional RAM is available in SQL Server 2005 and SQL Server 2008. SQL Server 2008
also provides additional support for dynamic additional CPUs or processors. These features
are known as Hot Add RAM and Hot Add CPUs. Despite these names, support also exists
for hardware removal. The RECONFIGURE command must be executed in SQL Server to
implement any such hardware change for SQL Server.
Requirements for Hot Add CPU
Requires special hardware that supports Hot Add CPU.
Requires the 64-bit edition of Windows Server 2008 Datacenter or the Windows Server
2008 Enterprise edition for Itanium-Based Systems operating system.
Requires SQL Server 2008 Enterprise edition.
SQL Server cannot be configured to use soft NUMA.
Requirements for Hot Add RAM
Requires special hardware that supports Hot Add RAM.
Requires SQL Server Enterprise and is only available for 64-bit SQL Server and for
32-bit SQL Server when AWE is enabled. Hot Add Memory is not available for 32-bit
SQL Server when AWE is not enabled.
Requires Windows Server 2003/2008, Enterprise and Datacenter editions.
S K I L L S U M M A RY
In this lesson, you reviewed the factors you need to consider when youre assessing the
capacity requirements of a database server. You studied a variety of methods for collecting
information about current capacity and how to forecast future needs. In addition, you
familiarized yourself with the techniques and skills youll need to achieve a balance between
business and technical requirements. Finally, you learned about the various hardware and
software considerations you should factor into your design plans, including hardware,
operating system, and software versions.
For the certification examination:
Be familiar with System Monitor counters. Know how to use the System Monitor tool and
which counters provide relevant information about system status. Know the techniques of
collecting a baseline, and when and how to use it.
Know the prerequisites. Know the requirements and limitations for installing the various
editions of SQL Server 2005, including what operating system, how much memory, and
the speed of CPU you need.
Understand the cost-benefit relationship between 32-bit and 64-bit processors. Be familiar
with the advantages and disadvantages of the two processor types.
26 | Lesson 1
Knowledge Assessment
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
1. Which of the following factors should be considered when projecting disk-storage
requirements?
a. Forecasted business growth
b. Historical trends
c. Index maintenance space requirements
d. All of the above
2. Which of the following file types should not be considered when determining the
amount of disk space used by the database files?
a. Database files
b. Database paging file
c. Database transaction logs
d. Full-text indexes
3. What can result if improper disk-space allocation causes SQL Server 2005 to
dynamically grow the database by requesting extra disk space from the operating system?
(Choose all that apply.)
a. Truncating of log files
b. Reduced network bandwidth
c. Disk/file fragmentation
d. Processor bottleneck
4. Which of the following are System Monitor counters that can be used to assess disk I/O
rates? (Choose all that apply.)
a. PhysicalDisk:Disk Read Bytes/sec
b. PhysicalDisk:Disk Write Bytes/sec
c. PhysicalDisk:Avg. Disk Queue Length
d. PhysicalDisk:Disk Modify Bytes/sec
e. All of the above
5. The length of time data must be retained is also referred to as what?
a. Lifetime of data
b. Data Retention Period (DRP)
c. Data estimation period
d. Longevity of data
6. In order to start the System Monitor tool, you should type which of the following
commands in the Run text box?
a. perfmon
b. sysmon
c. sysinfo
d. mssysmon
e. mmc
7. If regulatory requirements or internal procedures require the encryption of data, which
subsystems are directly impacted? (Choose all that apply.)
a. Physical storage
b. Memory
c. CPU
d. Network
e. SQL Server version
28 | Lesson 1
16. Which one of the following counters is used to determine the amount of memory used
by SQL Server connections?
a. SQLServer:MemoryManager:Total Server Memory
b. SQLServer:MemoryManager:Working Set
c. SQLServer:Buffer Manager:Connection Memory (KB)
d. SQLServer:Page Manager:Connection Memory (KB)
e. SQLServer:Memory Manager:Connection Memory (KB)
17. Which of the following may affect network traffic?
a. Backup schedules
b. Firewalls
c. Antivirus applications
d. Enabled network protocols
e. All of the above
18. Which of the following business requirements should be considered when modifying or
designing a database infrastructure?
a. Budgetary constraints
b. IT policies
c. Data security
d. Data availability
e. All of the above
19. During your survey, you determine that one of the existing database servers has an
800MHz Pentium III processor with 256 MB of RAM and a 400 GB hard drive, running Windows XP. Which version of SQL Server can you install on this machine?
a. Workgroup
b. Standard
c. Enterprise
d. Developer
e. None of the above
20. You want to install SQL Server 2005 Enterprise Edition on a 32-bit CPU machine.
Which operating systems can this machine use? (Choose all that apply.)
a. Windows 2003, Service Pack 1
b. Windows 2000 Professional, Service Pack 3
c. Windows XP, Service Pack 1
d. Windows 2000 Server, Service Pack 5
e. All of the above
Case Study
Examining the Infrastructure
Thylacine Savings & Loan Association is a large financial institution serving
approximately 1.6 million customers over a broad geographic area. The company is
headquartered in the city of Trevallyn, which also serves as northern headquarters,
with 407 employees. Three branch offices are located in Stratford (Eastern operations),
Belleville (Western), and Rock Hill (Southern).
The company currently has a 3 terabyte OLTP database that tracks more than 2 billion
transactions each year. The main database for all transactions and operations is located
in Trevallyn. Regional databases contain deposit/withdrawal information only, and the
headquarters database is updated daily from the regional offices.
Thylacines departmental database servers are dispersed throughout the headquarters
location.
The company is currently experiencing 4 percent annual growth and plans to expand
into four new markets at the rate of one new market every two years. The database is
growing at a rate of 6 percent per year and will exceed available hard disk space in the
future. Additionally, server capacity is overloaded, resulting in poor performance and
long delays. A large portion of the database data is historical information.
After lengthy consideration, Thylacine Savings & Loan has decided to upgrade its
database system to SQL Server 2005 and has hired you as a consultant database project
architect to address the companys current and future needs.
Use the information in the previous case study to answer the following questions.
1.
Briefly summarize the initial steps you should take before beginning capacity
planning.
2. Do you need to consider regulatory factors? If so, describe the impact theyre likely
to have on the various components of the infrastructures capacity.
3. Which would you give greater weight: the observed growth rate of a database or the
projected business growth rate of Thylacine Savings & Loan? Why?
Designing Physical
Storage
LESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Specify the number and placement of files to create for each database.
Foundational
Design instances.
Foundational
Foundational
Foundational
Decide on the physical storage for the tempdb database for each instance.
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
extent: A unit of space allocated to
an object. A unit of data input and
output; data is stored or retrieved
from the disk as an extent
(64 kilobytes).
filegroup: A named collection of
one or more data files that forms
In the previous lesson, you looked at the various physical requirements and considerations
associated with creating a hardware infrastructure for SQL Server database servers. Its important to remember that although you may tend to look at aspects of the hardware environment as separategrouping them in memory, disk space, network requirements, and so
onall these components are intrinsically tied to each another and interact together.
30
In this lesson, the focus is how to best design and organize physical storage. As you might guess,
the first thing youll learn is that there is no correct answer or magical formula that will work
every time in addressing this issue, any more than there was for assessing hardware requirements
in Lesson 1. One of the most elegant (and maddening) features of SQL Server is that it requires
the infrastructure designer to consider the interaction of all the components in designing the
optimal solution. Inadequate memory, for example, can have a profound influence on the
effectiveness of even the fastest hard disk.
With that in mind, you must examine how to design physical storage for your databases and
instances. To efficiently manage storage for your databases, you need to understand what
objects take up disk space and how SQL Server stores those objects. In SQL Server 2000, for
example, one simple system table tracks space usage, only two objects consume disk space, and
only three types of pages exist to store user data. This structure is relatively easy to manage, but
it also has its limitations, especially regarding how SQL Server stores and retrieves large object
(LOB) data.
SQL Server 2005 and SQL Server 2008 have an enhanced storage model that expands the
number and types of objects that consume space, gives you more flexible options for storing
variable-length LOB data, and adds functionality to store partitioned data in multiple,
different locations.
Disk input/output is measured in extent units (64 kilobytes). Every database has at least
two physical files: one for data entries and one for log entries. In both cases the size on disk
is allocated when you define a database. For data files, empty space is stored until an extent
is written. The files are Indexed Sequential Access Method (ISAM) structures. The Global
Allocation Map, Index Allocation Map, and Page Free Space are referenced dynamically to find
and recover the correct extent. The ISAM technique permits files to grow indefinitely and scale
to as large as you might need because never more than 64 KB is retrieved or written to disk.
If youve ever worked with data without a computer, youve almost certainly noticed that data
takes up a lot of physical space. In a nontechnical environment, that means boxes of paper,
lots of file folders, and a plan to keep them organized. Or it may entail miles of shelving filled
with vast numbers of files. It was this seemingly endless parade of paperwork (usually official
documents) and the practice of tying thick legal documents together with red cloth tape that
led to the phrase cutting through the red tape. The point is that paper data storage consumes physical space.
If youre using SQL Server 2005 to collect and store data for your enterprise, you dont have
quite the same space problem, and its highly unlikely that youll need to rent a warehouse to
hold your files and records. However, youll still have to address the issue of physical storage
and how to design it. Thats what you will learn in the following sections after we cover some
basic concepts.
Primary data files with an .mdf extension are the first files created in a database and can contain user-defined objects, such as tables and views, as well as system tables that SQL Server
32 | Lesson 2
requires for keeping track of the database. If the database gets too big and you run out of
room on your first hard disk, you can create secondary data files with an .ndf extension on
separate physical hard disks to give your database more room.
Secondary files can be grouped together into filegroups. Filegroups are logical groupings of
files, meaning that the files can be on any disk in the system and SQL Server will still see
them as belonging together. This grouping capability comes in handy for very large databases
(VLDBs), which are many gigabytes or even terabytes in size.
TAKE NOTE
Primary data files and any other files not specifically assigned to another filegroup belong
to the primary filegroup.
For the purpose of illustration, suppose you have a database that is several hundred gigabytes
in size and contains several tables. Suppose that users read from half of these tables quite a bit
and write to the other half quite a bit. Assuming that you have multiple hard disks, you can
create secondary files on two of your hard disks and put them in a filegroup called READ.
Next, create two more secondary files on different hard disks, and place them in a filegroup
called WRITE. Now, when you want to create a new table that is primarily for reading, you
can specifically instruct SQL Server to place it on the READ filegroup. The WRITE group
will never be touched. You have, to a small degree, load-balanced the system, because some
hard disks are dedicated to reading and others to writing. Using filegroups is more complex
than this in the real world, but you get the picture.
The third type of file is a transaction log file. Transaction log files use an .ldf extension and
dont contain any objects such as tables or views. To understand these files, its best to know a
little about how SQL Server writes data to disk.
Internally when a user initiates a change to some data (either an INSERT, UPDATE, or
DELETE statement), SQL Server first writes the transaction information out to the transaction log file. Following that action, SQL Server then caches the changed data in memory for
a short period of time. This process of updating the log file first is called a write-ahead log. As
changes to data accumulate, and at frequent intervals, SQL Server flushes the cached data by
performing actual writes to the database data file on disk.
Why should I want to do this? you may ask. There are two reasons. The first is speed.
Memory is about 100 times faster than hard disk, so if you pull the data off the disk and
make all the changes in memory, the changes occur about 100 times faster than they would
if you wrote directly to disk. The second reason to use transaction logs is for recoverability.
Suppose you backed up your data last night around 10:00 p.m. and your hard disk containing the data crashed at 11:00 a.m. the next day. You would lose all your changes since last
night at 10:00 p.m. if you wrote to only the data file. Because youve recorded the changes to
the data in the transaction log file (which should be on a separate disk), you can recover all
your data right up to the second of the crash. The transaction log stores transactions in real
time and acts as a sort of incremental backup.
Now, try to imagine the inside of these database files. Imagine what would happen if they had
no order or organizationif SQL Server wrote data wherever it found the space. It would
take forever for SQL Server to find your data when you asked for it, and the entire server
would be slow as a result. To keep this from happening, SQL Server has even smaller levels of
data storage inside your data files that you dont see, called pages and extents.
Understanding Pages
Pages are the smallest unit of storage in a SQL Server data file. Pages are 8,192 bytes
each and start with a 96-byte header. This means that each page can hold 8,096 bytes of
data. There are several different types of pages (not all listed here), each one holding a
different type of data:
Data. This type of page contains most of the data you enter into your tables. The only
kinds of data entered by users that arent stored in a data page are text and image data
because text and image data are usually large and warrant their own pages.
Text/image. The text, ntext, and image datatypes are designed to hold large objects,
up to 2 GB. Large objects such as pictures and large documents are difficult to retrieve
when theyre stored in a field in one of your tables because SQL Server returns the entire
object when queried for it. To break the large, unwieldy objects into smaller, more manageable chunks, text, ntext, and image datatypes are stored in their own pages. This way,
when you request SQL Server to return an image or a large document, it can return
small chunks of the document at a time rather than the whole thing all at once.
Index. Indexes are used to accelerate data access by keeping a list of all the values in a
single field (or a combination of multiple fields) in the table and associating those values
with a record number. Indexes are stored separately from data in their own page type.
Global Allocation Map. When a table requires more space inside the data file where it
resides, SQL Server doesnt just allocate one page at a time. It allocates eight contiguous
pages, called an extent. The Global Allocation Map (GAM) page type is used to keep
track of which extents are allocated and which are still available.
Index Allocation Map. Although the GAM pages keep track of which extents are in
use, they dont monitor the purpose for which the extents are being used. The Index
Allocation Map (IAM) pages are used to keep track of what an extent is being used
forspecifically, to which table or index the extent has been allocated.
Page Free Space. This isnt an empty page, as the name may suggest. Its a special type
used to keep track of free space on all the other pages in the database. Each Page Free
Space page can monitor the free space on up to 8,000 other pages. That way, SQL
Server knows which pages have free space when new data needs to be inserted.
Understanding Extents
An extent is a collection of eight contiguous pages used to keep the database from
becoming fragmented. Fragmentation means that pages that belong together, usually
belonging to the same table or index, are scattered throughout the database file. To avoid
fragmentation, SQL Server assigns space to tables and indexes in extents. That way, at
least eight of the pages should be physically next to one another, making them easier for
SQL Server to locate. SQL Server uses two types of extents to organize pages: uniform
and mixed.
Uniform extents are those entirely owned by a single object. For example, if a single table
owns all eight pages of an extent, its considered uniform. Mixed extents are used for objects
that are too small to fill eight pages by themselves. In that instance, SQL Server divvies up
the pages in the extent to multiple objects.
TAKE NOTE
Transaction logs arent organized into pages or extents. They contain a list of transactions
that have modified your data, organized on a first-come, first-served basis.
Dynamically adjusting file size proves to be an overhead expensive operation. Try to set file
allocations correctly through prior planning.
34 | Lesson 2
If there werent electronic databases or computers and your job was still to design physical
storage for your data, youd have to know how much data there was, its growth rate, and how
much more there will be. Armed with this information, youd estimate how many shelf feet it
would require (or convert to miles, if appropriate). Then, youd estimate the storage space you
needed and select a warehouse (or more than one) that met your requirements.
When you design a database, youll likely have to estimate how large the database will be
when filled with data. This makes sense when you consider that the old adage waste not, want
not rings true regarding hard-disk space on your SQL Server. Because databases are files that
are stored on your hard disk, you can waste hard-disk space if you make them too big. If you
make your database files too small, SQL Server will have to expand the database file, or you
may need to create a secondary data file to accommodate the extra dataa process that can
slow the system and users.
As youll see in more detail in Lesson 8, estimating the size of a database can also help determine whether the database design needs refining. For example, you may determine that the
estimated size of the database is too large to implement in your organization and that more
normalization is required. Conversely, the estimated size may be smaller than expected. This
would allow you to denormalize the database to improve query performance.
LAB EXERCISE
1. Calculate the record size of the table in question. This may not be easy to do as some
datatypes have variable lengths. For such columns estimate the average size and then sum
the actual or estimated size of each column in the table.
2. Divide 8,096 by the row size from step 1, and round down to the nearest number. The
figure 8,096 is the amount of data a single data page can hold, and you round down
because a row cant be split across pages.
3. Divide the number of rows you expect to have by the result from step 2. This tells you
how many data pages will be used for your table.
4. Multiply the result from step 3 by 8,192the size of a data page in bytes. This tells you
exactly how many bytes your table will take on the disk.
Youll try this process in Exercise 2.1.
Data Compression
SQL Server 2008 includes two new data compression features for reducing the diskspace requirementsrow compression and page compression. Only one type of
compression can be specified at a time on the same object. Compression can be used
on both regular tables and nonclustered indexes. Clustered indexes and views can be
considered as compressed if the data in the table is compressed since views and clustered
indexes are representations of the regular table data. The space savings with these
compression methods will, as with all forms of data compression, depend on the nature
of the data being compressed.
TAKE NOTE
Data Compression is
only available in the
Enterprise, Developer,
and Evaluation editions
of SQL Server 2008.
TAKE NOTE
Page Compression. Also compresses all columns in all rows in a table; however, the
method of compression spans multiple rows thus involving an entire page of data. Page
compression can be thought of as a higher or further level of compression because when
page compression is specified, row compression is done first, then the additional page
level compression is applied. The purpose of page compression is to reduce the amount
of redundant data stored in a page regardless of which row it is in. Thus page compression is preferred over row compression when the data on a page to be compressed has a
higher percentage of repetitive data as compared to unique data:
ALTER TABLE mytable REBUILD
WITH (DATA_COMPRESSION = PAGE);
Sparse Columns
SQL Server 2008 includes a new storage space savings feature known as Sparse
Columns. Even if a column often has NULL data, space must be allocated for the
column. The algorithm used in assigning space to columns of data can be complex
depending on the datatypes involved. SQL Server disregards the order in which columns
are specified in the CREATE TABLE command and reorganizes the columns that are
defined for the table into a group for fixed-size columns and a group for variable-length
columns. Using a sparse-column option for a fixed-length column potentially alters this
fixed-space allocation. When the majority of the rows in a table have null data for a
particular column, then that column is a probable candidate for use as a sparse column.
Defining a column as sparse can actually increase the space used if the majority of the
rows have data in the column. Sparse columns also require some additional processing
overhead so like most things, using sparse columns is a trade-off and you should use
your best judgment depending on the data.
A considerable number of rules must be followed when using sparse columns. Here is a list to
remember:
Every sparse column must be nullable.
No default value constraint or rule can be applied to a sparse column.
The column options IDENTITY and ROWGUIDCOL cannot be used on a sparse
column.
All datatypes and attributes of datatypes are supported except for GEOGRAPHY,
GEOMETRY, TEXT, NTEXT, IMAGE, TIMESTAMP, VARBINARY (MAX), and
FILESTREAM.
User-defined datatypes cannot be sparse.
A table with one or more sparse columns cannot be compressed.
36 | Lesson 2
TAKE NOTE
A computed column cannot be sparse; however, a sparse column could be used to calculate a computed column.
Sparse columns cannot be used where merge replication is used.
Sparse columns cannot be part of a clustered index nor part of a primary key.
A sparse column can be implemented simply by adding the key word SPARSE to the column
definition. The following example shows how this can be done:
CREATE TABLE address(
addressid
INT PRIMARY KEY,
streetinfo1 CHAR(50) NULL,
streetinfo2 CHAR(50) NULL SPARSE,
city_name
CHAR(20) NULL,
statecd
CHAR(2),
zipcode
CHAR(9)
);
REF
Data compression
features are also new in
SQL Server 2008. See
Lesson 2.
TAKE NOTE
Because sparse columns normally should have a high percentage of null-valued rows,
filtered indexes are appropriate for these columns. A filtered index on a sparse column can
index only those rows that have actual values. This results in a smaller and more efficient
index on the column.
Understanding RAID
Placing database files in the appropriate location is highly dependent on the available
hardware and software. There are few hard-and-fast rules when it comes to databases. In
fact, the only definite rule is that of design. The more thoroughly you plan and design
your system, the less work it will be later, which is why its so important to develop a
good capacity plan.
You must keep several issues in mind when youre deciding where to place your database files.
They include planning for growth, communication, fault tolerance, reliability, and speed.
When disks are arranged in certain patterns and use a specific controller, they can be a
Redundant Array of Inexpensive Disks (RAID) set. RAID is one of the best measures you can
take to ensure the reliability and consistency of your database.
REF
Lesson 10 discusses
RAID and its role in
assuring high availability.
For speed and reliability, its better to have more disks, and the faster the better. SCSI-type
disks are typically faster than IDE, although theyre slightly more difficult to configure. SATA
and SAS disks may make excellent choices for both speed and reliability. RAID controllers
typically support only one type of drive interface so your choices for a controller and drives
must match each other. Note further that for non-SCSI drives, different RAID controllers
support different quantities of drives based on the number of connectors. This potential
limitation must be taken into account as well as the physical number of drives that can be
installed in a cabinet.
Several numbers are associated with RAID, but the most common are 0, 1, 5, and 10 as
shown in Table 2-1. Each has its own features and drawbacks.
RAID 0 uses disk stripingit writes data across multiple hard-disk partitions in what is called
a stripe set. This can greatly improve speed because multiple hard disks are working at the
same time. Although RAID 0 gives you the best speed, it doesnt provide any fault tolerance.
If any one of the hard disks in the stripe set is damaged, you lose all your data.
RAID 1, called disk mirroring, writes your information to disk twiceonce to the primary drive
and once to the mirror drive. This gives you excellent fault tolerance, but its fairly slow because
you must write to disk twice to two different hard drives. RAID 1 is optimized for fast reads.
CERTIFICATION READY?
Know the different types
of RAID and what types
are preferred for different
situations.
RAID LEVEL
DESCRIPTION
RAID 0
RAID 1
RAID 5
RAID 10
RAID 5 requires at least three physical drives and works by writing parts of data across all
drives in the set. Parity checksums are also written across all disks in the stripe set, giving you
excellent fault tolerance because the parity checksums can be used to re-create information
lost if a single disk in the stripe set fails. To understand this, think of a math problem like
3 2 5. Now think of one drive storing the number 3 and the other storing 2, with
5 as the parity checksum. If you remove one of the drives, you can re-create the lost data
by referring back to the other two: For example, x 2 5 means that x 3. However,
if more than one disk in the stripe set fails, youll lose all your data. RAID 5 is often called
stripe set with parity.
RAID 10 is a combination of both RAID 1 and RAID 0. This level of RAID should be used
in mission-critical systems that require uptime 24 hours a day, 7 days a week, and the fastest
possible access. RAID 10 implements striping and then mirrors the stripe sets. You still have
excellent speed and excellent fault tolerance, but you also have the added expense of using
twice the disk space of RAID 0. Because it doesnt store a parity bit, its fast, but it duplicates
the data on four or more drives to be safe. This type of RAID is best for a situation that that
can afford no SQL Server downtime.
TAKE NOTE
This discussion covers hardware RAID. Windows Server operating systems also provide
RAID implemented in software. Generally hardware RAID is faster. With software RAID,
all functions that would be handled by a hardware RAID controller must be handled in
software, which introduces an extra load on the server.
The write-ahead log ensures data integrity through mishaps such as a power failure. Always
train your data-entry people to check their last submission following a disaster to ensure the
transaction actually survived the catastrophe.
Every SQL Server database has a transaction log that records all transactions and the database
modifications made by each transaction. Think of it as an ongoing collection of everything
that has happened to your databasea diary of database doings.
The transaction log is a critical component of the database, and if there is a system failure,
the transaction log may be required to bring your database back to a consistent state. For that
reason, the transaction log should never be deleted or moved unless you fully understand the
ramifications of doing so.
38 | Lesson 2
If the end of the logical log reaches the start of the logical log, then one of two things occurs.
If the FILEGROWTH setting is enabled for the log and space is available on the disk, the file
is increased by the amount specified in the GROWTH_INCREMENT setting and the new
log records are added to the extension. If the FILEGROWTH setting isnt enabled, or the
disk that is holding the log file has less free space than the amount specified in GROWTH_
INCREMENT, a 9002 error is generated.
TAKE NOTE
If the log contains multiple physical log files, the logical log will move through all the
physical log files before it wraps back to the start of the first physical log file.
TAKE NOTE
REF
Lesson 11 discusses
recovery models.
Truncation doesnt reduce the size of a physical log file. Reducing the physical size of a log
file requires shrinking the file.
40 | Lesson 2
Figure 2-1
Typical results from DBCC
SQLPERF (LOGSPACE)
To get information about the current size of a log file, its maximum size, and the autogrow
option for the file, you can also use the size, max_size, and growth columns for that log file in
sys.database_files.
LAB EXERCISE
You should reduce the risk of damage to your transaction log by locating it on fault-tolerant
storage. A prudent precaution is to also make multiple copies of log backups by backing up the
log to disk and then copying the disk file to another device, such as a separate disk or tape.
The first line of defense against a disaster is your backup. Do it regularly. Store the media in a
location where, if you have a fire, they wont burn along with your server room.
In SQL Server, youre limited to placing database files on what SQL Server deems to be a
local hard disk. Your local hard disks can be on your local machine or on a hardware device
that is connected directly to the SQL Server machine (such as a hardware RAID array).
Although you have this limitation with your active database files, this rule doesnt apply to
your backups. Backups can be placed anywhere in your enterprise, using named pipe, shared
memory, TCP/IP and VIA protocols on local hard disks, networked hard disks, and tape.
42 | Lesson 2
TAKE NOTE
A transaction log backup can be larger than a database backup. Suppose, for example, that
you have a database with a high transaction rate. In that case, the transaction log will grow
quickly. The best approach will be to create transaction log backups more frequently.
There are three types of transaction log backups. A pure log backup contains only transaction log records for an interval, without any bulk changes. A bulk log backup includes log
and data pages changed by bulk operations. In this type of backup, point-in-time recovery
isnt allowed. A tail-log backup is taken from a possibly damaged database to capture the log
records that havent yet been backed up. A tail-log backup is taken after a failure in order to
prevent work loss and can contain either pure log or bulk log data.
CERTIFICATION READY?
You remembered to back
up the current log (tail
log) after a catastrophic
data disk failure. Congratulations! When you
restore this log is it
with the /RECOVERY or
/NORECOVERY switch?
Making regular transaction log backups is an essential step in your database design, as youll
see in Lesson 11. As you already learned, in addition to permitting you to restore the backedup transactions, a log backup truncates the log to remove the backed-up log records from
the log file. If you dont back up the log frequently enough, the log files can fill up. If you
lose a log backup, you may not be able to restore the database past the preceding backup.
Therefore, you should store the chain of log backups for a series of database backups.
If your most recent full database backup is unusable, you can restore an earlier full database backup
and then restore all the transaction log backups created since that earlier full database backup.
Because of the crucial role transaction log backups play in restoring a damaged database, you
should make multiple copies of log backups by backing up the log to disk and then copying
the disk file to another device, such as a separate disk or tape.
Backup Compression
SQL Server 2008 includes an easy-to-implement method of incorporating compression
when conducting database backups. Backups can be set to automatically use compression
via a new database option. This new option is set on the Database Settings node of the
Server Properties. This option setting can be overridden by specifying in the BACKUP
command whether or not compression should be performed. When restoring from a
compressed backup, no additional command syntax is necessary as SQL Server 2008
handles the decompression automatically. Be aware however that a compressed backup
would not be readable by an earlier version of SQL Server.
An example of the command syntax for using compression in a backup is shown next:
BACKUP DATABASE AdventureWorks TO DISK =
C:\SQLServerBackups\AdventureWorks.Bak
WITH COMPRESSION
TAKE NOTE
Note that the ability to create backups with compression is only available with the
Enterprise, Developer, and Evaluation editions of SQL Server 2008. All editions of SQL
Server 2008 can restore a compressed backup.
A database guideline has evolved. Use three spindles: one for the operating system, one for
the data, and one for the log. With SQL Server you may also want one for TempDB. Add
additional drives (spindles) maintaining these three (or four) categories.
To ensure the maximum utilization of resources while enhancing security for your database
server, you should install the operating system files on a spindle separate from data and
applications. In the case of SQL Server, you should install the Windows operating system
on a separate drive with or without SQL executables, where the page file will be. NTFS
5.0, introduced with Windows 2000, supports both file encryption and compression. By
default, these two features are turned off on a newly installed Windows 2000, 2003, or 2008
Server. Although these features do provide some benefits under limited circumstances, they
dont provide any benefits for SQL Server. SQL Server is very I/O intensive, and anything
that increases disk I/O hurts SQL Servers performance, so using either of these features can
greatly hurt performance.
Both file encryption and compression significantly increase disk I/O because data files have
to be manipulated on the fly as theyre used. If either of these settings have been activated by
accident, you should turn off this feature.
TAKE NOTE
SQL Server 2008 introduces compressible rows and pagesslightly different concepts
than the operating system solutionthat may result in faster I/O. Study BOL topics on
Compression Implementation to see if these methods will work for you.
Generally, place SQL Server files on the operating system spindle. Generally, change the
owner of services to a domain user and provide that service owner with only the rights and
permissions needed.
Each service in SQL Server represents a process or set of processes. Depending on the
Microsoft SQL Server components you choose to install, SQL Server 2005 Setup installs the
following 10 services:
You should install only the services youll be using with SQL Server 2005.
44 | Lesson 2
On all supported operating systems, SQL Server and SQL Server Agent run as Microsoft
Windows services. For SQL Server and SQL Server Agent to run as services in Windows,
SQL Server, and SQL Server Agent must be assigned a Windows user account. Typically,
both SQL Server and SQL Server Agent are assigned the same user accounteither the local
system or a domain user account. However, you can customize the settings for each service
during the installation process.
TAKE NOTE
Program files and data files cant be installed on a removable disk drive, on a file system that
uses compression, or on shared drives on a failover cluster instance.
Dynamic tables require backup frequently. Static tables need to be backed up just once.
Analyze your system. Create filegroups to manage your database objects efficiently.
SQL Server maps a database over a set of operating-system files. Data and log information are
never mixed in the same file, and individual files are used by only one database. As explained
earlier, filegroups are named collections of files and are used to help with data placement and
administrative tasks such as backup and restore operations.
SQL Server data and log files can be put on either FAT or NTFS partitions, with NTFS
highly recommended because of its security aspects. Read/write data filegroups and log files
cant be placed on a compressed NTFS file system. Only read-only databases and read-only
secondary filegroups can be put on a compressed NTFS file system.
TAKE NOTE
Although the .mdf, .ndf, and .ldf filename extensions arent required, its a good idea to use
them because they help you identify the different kinds of files and their use.
The locations of all the files in a database are recorded in the primary file of the database and
in the master database. SQL Server uses the file location information from the master database most of the time. In the following situations, it uses the file location information in the
primary file to initialize the file location entries in the master database:
When attaching a database using the CREATE DATABASE statement with either the
FOR ATTACH or FOR ATTACH_REBUILD_LOG option
When upgrading from SQL Server version 2000 or version 7.0 to SQL Server 2005
When restoring the master database
Setting Up Filenames
Each SQL Server file has two different names. The logical_file_name is used to refer to
the physical file in all Transact-SQL statements. The logical filename must comply with
the rules for SQL Server identifiers and must be unique among logical filenames in the
database. The OS_file_name is the name of the physical file, including the directory
path. It must follow the rules for operating system filenames.
Primary filegroups. Contains the primary data file and any other files not specifically
assigned to another filegroup. All pages for the system tables are allocated in the primary
filegroup.
User-defined filegroups. Any filegroups that are specified by using the FILEGROUP
keyword in a CREATE DATABASE or ALTER DATABASE statement.
No file can be a member of more than one filegroup. Tables, indexes, and large object data can
be associated with a specified filegroup. In this case, all their pages are allocated in that filegroup, or the tables and indexes can be partitioned. The data of partitioned tables and indexes
is divided into units, each of which can be placed in a separate filegroup in a database.
One filegroup in each database is designated the default filegroup. When a table or index is
created without specifying a filegroup, its assumed that all pages will be allocated from the
default filegroup. Only one filegroup at a time can be the default filegroup. If no default filegroup is specified, the primary filegroup is the default filegroup.
Designing Instances
THE BOTTOM LINE
Instances are isolated from each other. Someone with permission to access one instance
(normally) cannot access another instance.
An instance is a single installation of SQL Server. There are two types of SQL Server instances:
Default instance. The first installation of SQL Server on a machine is the default
instance. It doesnt have a special network name; it works by using the name of the
46 | Lesson 2
computer, just like always. The names of the default services remain MSSQLServer and
SQLServerAgent. If you have older SQL client applications that use only the computer
name, then you can still use those against the default instance. You can have only a
single default instance running at any given time.
Named instance. SQL Server can be installed multiple times (in different directories)
on the same computer. In order to run multiple copies at the same time, a named
instance is installed. With a named instance, the computer name and the name of the
instance are used for the full name of the SQL Server instance. For example, if the
server GARAK has an instance called SECOND, the instance is known by GARAK\
SECOND, and GARAK\SECOND is used to connect to the instance, as shown in
Figure 2-2.
Figure 2-2
Connecting to a named
instance
One of the first decisions you have to make when installing SQL Server 2005 is whether to
use a default or named instance. Use the following guidelines in making your decision:
If youre upgrading from SQL Server 7.0, the upgraded instance must be created as a
default instance.
If you only plan to install a single instance of SQL Server on a database server, it should
be a default instance.
If you must support client connections from SQL Server 7.0 or earlier, its easier to use a
default instance.
TAKE NOTE
SQL Server allows you to install a named instance without installing a default instance. This is
useful when you plan to have multiple instances on the same computer because the server can
host only one default instance. You can have a default instance and multiple named instances
on the same server, but its simpler if every instance has the same naming convention.
Any application that installs SQL Server Express edition should install it as a named instance.
Doing so minimizes conflict in situations where multiple applications are installed on the
same computer.
A single server has only so many CPUs and a certain amount of RAM. Since each instance
requires its fair share of resources, you must continue that balancing act you have been
learning. At what point does performance to the other instances suffer?
As youve seen, SQL Server supports multiple SQL Server instances on a single server or
processor. Only one instance can be the default instance; all others must be named instances.
A computer can run multiple instances of SQL Server concurrently, and each instance runs
independently of other instances. All instances on a single server or processor must be the
same localized version of SQL Server 2005.
Table 2-2 shows the number of instances supported for each instance-aware component in the
different editions of SQL Server 2005.
Table 2-2
Number of instances per SQL
Server 2005 edition and
component
TAKE NOTE
REF
SQL S ERVER
2005 E DITION
D ATABASE E NGINE
I NSTANCES
A NALYSIS S ERVICES
I NSTANCES
R EPORTING S ERVICES
I NSTANCES
Enterprise or
Developer
50
50
50
Standard,
Workgroup, or
Express
16
16
16
Based on business requirements, you need to determine the number of instances that must
be installed on a database server. You can use several instances to isolate databases on a single
server. Doing so safeguards the databases from inadvertent configuration changes. However,
each instance has certain resource requirements, and running too many instances increases the
management overhead of the operating system.
The number of instances you can install always depends on the resources available on your
server and the resources that each instance requires. Sometimes its possible to sum the individual resource requirements for CPU, memory, and I/O, and get a reasonably good idea of
how many instances can fit.
Usually, if you have enough memory and disk space with SQL Server, you can get about four
instances comfortablymaybe one or two more, if theyre low-power-consumption instances.
Add many more than that, and you can run into disk trouble.
Generally speaking, one SQL Server instance will outperform two or more instances on the
same hardware, because there is some overhead for the instances themselves. If your first
instance isnt hitting a performance bottleneck, having a second instance always reduces the
resources available to both instances because the second instance maintains both the second
copy of SQL Server and its own copies of the query plans for its data.
Your obvious goal is to find a way to achieve a balance between isolation, manageability, and
resources.
As with all objects, establish a naming convention that makes sense in your environment.
Because of the large number of instances you can potentially have across an enterprise,
establishing a naming convention at the outset is good practice. Each instance must have a
unique name. The names should be short but descriptive. Pay careful attention to creating
naming conventions, avoiding cryptic names as much as possible. If the instances arent
named clearly, you may make mistakes when accessing them. Remember that an instance
cant be renamedonce a name is assigned, thats it.
48 | Lesson 2
Keep in mind the following caveats and requirements when youre creating a SQL Server
instance name:
Instance names are limited to 16 characters.
Instance names are case insensitive.
An instance cant be renamed. If you change the name of the computer, that portion of
the name changes, but not the instance name.
Instance names cant contain Default, MSSQLServer, or other reserved keywords.
The first character in the instance name must be a letter or an underscore ( _ ).
Subsequent characters can be from other national scripts, the dollar sign ( $ ), or an
underscore ( _ ).
Embedded spaces or other special characters arent allowed in instance names, nor are
the backslash ( \ ), comma ( , ), colon ( : ), semicolon ( ; ), single quote ( ), ampersand
( & ), or at sign ( @ ).
TAKE NOTE
Only characters that are valid in the current Microsoft Windows code page can be used
in SQL Server instance names. Also it is probably a good practice to not use complicated
instance names.
The name you give an instance is a virtual name. When creating directories and files, SQL
Server Setup uses the instance ID it generates for each server component. The server components in SQL Server 2005 are the Database Engine, Analysis Services, and Reporting Services.
The instance ID is in the format MSSQL.n, where n is the ordinal number of the component being installed. The instance ID is used in the file directory and the registry root. For
instance, if you install SQL Server and include Analysis and Reporting Services, the instance
ID will be three different numbers, and each server component will have its own instance ID.
The first instance ID generated is MSSQL.1; ID numbers are incremented for additional
instances as MSSQL.2, MSSQL.3, and so on. To confuse things a little further, if gaps occur
in the ID sequence because youve uninstalled a component or an entire instance, subsequent
installs result in SQL Server generating ID numbers to fill the gaps first. Hence, the most
recently installed instance may not always have the highest instance ID number.
TAKE NOTE
CERTIFICATION READY?
Expect some exam
questions combining
RAID, filegroups, and
possibly multiple
instances. Can a new
instance be created using
a RAID 5 array already in
use by another instance?
If so, where should the
data files and log files be
located if multiple drive
letters and arrays are
available?
SQL Server 2008 identifies instances slightly differently. The default path name is still
Program Files\Microsoft SQL Server but then deviates from SQL Server 2005 in that
the component is identified (e.g., MSAS10 for Analysis Services, MSRS10 for Reporting
Services, and MSSQL10 for the OLTP Database Engine).
Server components are installed in directories with the format <instanceID>\<component
name>. For example, a default or named instance with the Database Engine, Analysis
Services, and Reporting Services has the following default directories:
<Program Files>\Microsoft SQL Server\MSSQL.1\MSSQL\ for the Database Engine
<Program Files>\Microsoft SQL Server\MSSQL.2\OLAP\ for Analysis Services
<Program Files>\Microsoft SQL Server\MSSQL.3\RS\ for Reporting Services
Instead of <Program Files>\Microsoft SQL Server, a <custom path> is used if the user chooses
to change the default installation directory.
SQL Server 2005 Integration Services, Notification Services, and client components arent
instance aware and, therefore, arent assigned an instance ID. Non-instance-aware components
are installed to the same directory by default: <system drive>:\Program Files\Microsoft SQL
Server\90\. Changing the installation path for one shared component also changes it for the
other shared components. Subsequent installations install non-instance-aware components to
the same directory as the original installation.
Only so many instances can be supported on a single server. If you need more instances,
you must procure more servers. This involves hardware, software, and licenses.
Determining how many physical servers youll need and determining how many databases
you should create both depend on the same factors. The total number of databases or
instances on a particular server isnt all that relevant. What is important is how busy each of
the databases is (and, to a certain degree, the size of the databases in relation to the size of the
available disk space). You can have servers with only one very busy database, and other servers
with many, many databases (all little used). The same logic applies to instances.
You must consider the total overall load on each physical SQL Server, not the total number
of databases on each server (unless database size is an issue). As you saw in Lesson 1, System
Monitor can be used to help you determine whether a particular SQL Server currently is
experiencing bottlenecks.
If youll be setting up one or more new SQL Servers, determining how many databases
should be on each server isnt an easy task, because you probably dont know what the load on
each database will be. In this case, you must make educated guesses about database usage to
best distribute databases among multiple SQL Servers and get the biggest performance benefits. And once you get some experience with the databases in production, then you can move
them around as appropriate to balance the load.
TAKE NOTE
As pointed out in
the Deciding How to
Name Instances section,
SQL Server 2008 has a
slightly different path
structure.
D ATABASE
master
D ATABASE F ILE
Master.mdf
L OG F ILE
Mastlog.ldf
model
Model.mdf
Modellog.ldf
msdb
Msdbdata.mdf
Msdblog.ldf
tempdb
Tempdb.mdf
Templog.ldf
The SQL Server installation process prompts you to select the physical location of the files
belonging to the system databases if you want to use a location rather than the default.
System databases contain information used by SQL Server to operate. You then create user
databases, which can contain any information you need to collect. You can use SQL Query
Analyzer to query any of your SQL databases, including the system and sample databases.
50 | Lesson 2
Table 2-4 describes the type of information stored in each of the default databases.
Table 2-4
System database contents
TAKE NOTE
D ATABASE
distribution
C ONTENTS
History information about replication. SQL Server creates this database on your server only if you configure replication.
master
model
msdb
tempdb
An additional system database, the Resource database, is a read-only database that contains all the system objects included with SQL Server. Its usually hidden in Management
Studio. The only supported user action is to move the Resource database to the same location as the master database.
Normally, youll leave the system databases in the default installation directory. However, you
may have to move a system database in the following situations:
Failure recovery (For example, the database is in suspect mode or has shut down because
of a hardware failure)
Planned relocation
Relocation for scheduled disk maintenance
TAKE NOTE
Common files used by all instances on a single computer are installed in the folder systemdrive:\Program Files\Microsoft SQL Server\90, where systemdrive is the drive letter where
components are installed. Normally this is drive C:.
LAB EXERCISE
In Exercise 2.3, youll see where the system database files are located.
The faster the drive assigned to tempdb the faster your database will be. A separate spindle
may be justified.
The tempdb system database is a global resource available to all users connected to the instance
of SQL Server. The tempdb system database is like a scratchpad for SQL Server and a place
where temporary information and intermediate result sets are stored. Earlier versions of SQL
Server made some use of the tempdb database, but SQL Server 2005 takes that a step further.
The new version uses the tempdb database heavily to support features such as row versioning
for triggers, online indexing, Multiple Active Result Sets (MARS), and snapshot isolation.
Consequently, you must be careful when determining the size and location of tempdb. In
addition, you should ensure that each instance has adequate throughput to the disk volumes
on which tempdb is stored.
Because it serves the same role as the reams of notepaper on which a writer outlines ideas, the
tempdb database is volatile, and no effort is made to save it from session to session. Instead,
tempdb is re-created each time the instance of SQL Server is started, and the system always
starts with a clean copy of the database. Temporary tables and stored procedures are dropped
automatically on disconnect, and no connections are active when the system is shut down.
For that reason, SQL Server doesnt allow backup and restore operations on the tempdb
system database.
TAKE NOTE
Because tempdb is re-created each time the instance of SQL Server is started, you dont
have to physically move the data and log files. The files are created in the new location
when the service is restarted. Until then, tempdb continues to use the data and log files in
the existing location.
The size and physical placement of the tempdb system database can affect the performance of
a system. For example, if the size that is defined for tempdb is too small, part of the systemprocessing load may be taken up with autogrowing tempdb to the size required to support the
workload every time you restart the instance of SQL Server. You can avoid this overhead by
increasing the size of the tempdb database and log file.
Determining the appropriate size and location for tempdb in a production environment
depends on many factors. As described previously, these factors include the existing workload
and the SQL Server components and other features that are used.
Whenever possible, place the tempdb system database on a fast I/O subsystem. Use disk striping if there are many directly attached disks. You should also put the tempdb database on
disks other than those being used for the user databases.
For optimal tempdb performance, you can make some critical settings to the configuration
of tempdb. (SQL Server Books Online contains excellent information on how to optimize
tempdb usage that is beyond the scope of this book.)
Set the recovery model of tempdb to Simple to automatically reclaim log space. This
keeps space requirements small.
Set files to automatically grow when they need additional space. This allows the file to
grow until the disk is full.
Set the file growth increment to a reasonable level. You want to keep the tempdb database files from growing by too small a value, causing tempdb to constantly use resources
to expand, which adversely impacts performance. Microsoft recommends the following
general guidelines for setting the file-growth increment for tempdb files.
TEMPDB
F ILE S IZE
0 to 100 MB
100 to 200 MB
20 MB
200 MB or more
10%
Preallocate space for all tempdb files by setting the file size to a value large enough to
accommodate the typical workload in the environment.
52 | Lesson 2
LAB EXERCISE
In Exercise 2.4, youll modify the tempdb databases size and growth parameters.
TAKE NOTE
SQL Server Configuration Manager combines the functionality of the following SQL
Server 2000 tools: Server Network Utility, Client Network Utility, and Service Manager.
TAKE NOTE
When youre assigning ports, make sure they dont conflict with port numbers that are
already reserved by software vendors. To determine which port numbers are available,
visit the Internet Assigned Numbers Authority (IANA) Web site at the following URL:
www.iana.org/assignments/port-numbers.
Figure 2-3
SQL Server Configuration
Manager is the preferred tool
to manage many aspects of
SQL Server instance configurations, including services.
LAB EXERCISE
54 | Lesson 2
S K I L L S U M M A RY
Physical storage is a prime consideration when youre planning a SQL Server database
infrastructure. In this lesson, weve reviewed best practices and parameters for storing
the transaction log and backup file. Youve had a brief introduction to RAID and how it can
be used to both assure fault tolerance and optimize your storage system.
Placement of files also plays an important role on performance, and youve learned the
information youll need to use in deciding where to install the operating system, SQL Server
service executables, files created for databases, and system databases, especially tempdb.
Youve also learned that there is no magic answer about where to place files, but that your
decision in this regard will have a ripple effect across your database server.
You learned about default and named instances and how they both expand your flexibility
and ability to customize your database infrastructure while bringing along their own set of
considerations. Youve learned basic functions such as deciding on the number of instances
and naming conventions. Youve also learned when and where to use default and named
instances.
You learned how to set service requirements specific to your database server needs. Finally, you
learned how to use SQL Server Configuration Manager to administer services and instances, as
well as network protocols.
In the next lesson, youll learn how to combine the material youve learned here and in
Lesson 1 to develop a database-consolidation strategy.
For the certification examination:
Be familiar with transaction logs and their storage needs. Its important that you know the
growth characteristics of transaction log files and how they impact your physical storage
design. Make sure you understand the effect truncation and shrinking have on transaction logs.
Know the different types of RAID. Its important that you be able to differentiate between the
different types of RAID and understand which type should be applied in what circumstances.
You should be aware of the relative impact each RAID type has on read-and-write operations.
Be familiar with system databases. What is their role? What do they do, and how do you differentiate among them? Make sure you have a clear idea of the effect placement of the system
databases has on overall performance and the circumstances in which they should be moved.
Understand the impact of the tempdb system database. Be certain you know the role of
the tempdb system database in an instance and the design considerations surrounding its
physical storage. Be familiar with the recommendations for the initial size of tempdb in
different situations as well the growth increment.
Understand default and named instances. You should know the basic difference between
them and the circumstances under which a named instance is more appropriate than a
default instance, and vice versa.
Know how to administer instances. You should understand the basics of choosing the
proper naming and number of instances for your infrastructure.
Knowledge Assessment
Case Study
Mullen Enterprises
Mullen Enterprises provides database-hosting services for companies in the health
care industry. The company is now offering a new hosting service based on SQL
Server 2005.
Mullen Enterprises has a single office. Customers connect to the company network
through private WAN connections and via the Internet.
Planned Changes
The company plans to implements new SQL Server 2005 computers named Dublin,
Shannon, and Cork to host customer databases.
Business Requirements
Each customer can host up to five databases. Databases for a given customer are always
hosted on the same server. Each customer uses his or her own naming schema. Because
all customers are in the health care industry, most customers give their databases similar
names such as Patients, Doctors, Medications, and so on.
Performance
The company wants to maintain a minimal number of SQL Server 2005 instances and
servers.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions.
1. You need to design a strategy for identifying the number of instances that any one SQL
Server computer will support. What should you do?
a. Specify that each server must have one service for each customer.
b. Specify that each server must have only one instance.
c. Specify that each server must have one instance for each database that is hosted on
the server.
d. Specify that each server must have one instance for each customer who has one or
more databases that are hosted on the server.
2. You plan to have the Cork server contain three customers: Yanni HealthCare Services,
Kelly Hospitals, Inc., and The Curtin Clinic. Following your guidelines that each server
must have one instance for each customer who has one or more databases hosted on the
server, which of the following should you do?
a. Create a default and two named instances. Place the customers with the largest
performance need on the default instances, and place each of the other customers
on their own named instance.
56 | Lesson 2
Designing a
Consolidation Strategy
LESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY
SKILL
EXAM
OBJECTIVE
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
deploying: Migrating and
stabilizing your database servers
in the consolidated environment.
developing: Designing a
database migration plan for
the consolidated environment,
SQL Server is a powerful data platform capable of handling many different applications
at once. However, in most cases, each application has its own dedicated SQL Server that
is underutilized. This results in greater costs than necessary to many businesses, usually
for two reasons. First, often the DBAs dont want to chance decreased performance with
multiple applications using the same database server, so they separate each one on its
own SQL Server. Second, application developers or network administrators dont realize
that the database isnt synonymous with the server, so they require a new server for each
application.
Building on the capabilities of SQL Server 2000 and greatly extending its limits, SQL
Server 2005 is a platform geared to consolidate many SQL Server 2000 instances into
fewer SQL Server 2005 servers. This Lesson looks at the terminology and pros and cons
of consolidations, and how you may want to proceed when developing a strategy for your
environment.
This Lesson looks at a consolidation strategy in four phases based on the Microsoft Solutions
Framework (MSF):
58
TAKE NOTE
Envisioning
Planning
Developing
Stabilizing
Deploying
The stabilizing phase has been omitted in this discussion because it is largely an action
rather than a planning phase. During the stabilizing phase, the team performs integration,
load, and beta testing on the solution. In addition, the team tests the deployment scenarios
for the solution. The team focuses on identifying, prioritizing, and resolving issues so that
the solution can be prepared for release. During this phase, the solution progresses from
the state of all features being complete as defined in the functional specification for this
version to the state of meeting the defined quality levels. In addition, the solution is ready
for deployment to the business.
One note before going further: Your consolidation plan will be unique because of the wide
variety of variables that occur with each set of servers. This Lessons discussion assumes you
understand your environment and can extrapolate the advice and details given to make the
most informed decisions for your company.
Phase 1: Envisioning
THE BOTTOM LINE
When youre creating a consolidation plan, the first step is to consider its value by examining
the current SQL Server environment and gathering the information about the infrastructure.
The following sections highlight the main steps of envisioning the consolidation plan.
Forming a Team
Before you decide whether consolidation is a good idea for your organization, you need
to form a team to plan, create, and test your consolidation strategy. This team needs to
be involved from the start, so members have input on the benefits and drawbacks of
consolidation for the company.
The consolidation effort wont be quick or easy, and its too difficult for one person to
manage. Even in a small company where a single IT employee may be in charge of the
consolidation effort, this person will still need input and assistance from other aspects of the
60 | Lesson 3
It isnt always a clear-cut case that youll want to consolidate your SQL Server instances.
However, some good reasons exist for going through a server consolidation. The following
sections cover the main reasons you should consider consolidation.
CONSIDERING COSTS
The first reason companies look at server consolidation is cost. You should consider a few
types of costs, but first look at hard coststhose you must pay for immediately, such as the
SQL Server license. Each SQL Server you install costs money for the server software. There
may be a simple fee for the software or there may be per-processor costs and possibly longterm maintenance contracts. Microsoft offers discounts for business categories (government,
education, many others) for which you will undoubtedly qualify but this remains a significant
cost for many businesses.
Hard costs are easy to quantify and calculate because they represent actual money being spent
by the company. Other costs, called soft costs, are harder to list because they consist of missed
chances for revenue or savings.
IT people are often paid salaries; or, if your company outsources your IT support, there may
be a fixed cost for the service. But every server you add requires time to set up, install, administer, patch, and so on. Soft costs can be hidden because companies dont raise the IT administrators salary each time a new server is added. Instead, the greater workload takes away from
the administrators ability to perform other work because of a lack of time. Or it may cause a
lack of desire to improve other areas because administrators feel overloaded and taken advantage of as the number of servers they must support grows.
A great example is the database administrators (DBA) position. If a companys DBA has two
SQL Server instances to administer, time should be available after monitoring logs, patching,
and so on, to tune these servers, proactively rewrite queries, and perform other tasks that are
important to a smooth running SQL Server. However, if the same DBA is required to handle
five servers, then there is less time to devote to each server. For a small business, the DBA is
probably also the system administrator. Overload is much more likely because that person
may also be responsible for file servers, mail servers, web servers, and other systems. Salary
costs are the biggest component of IT, so it behooves a company to minimize staffing requirements. Consolidation helps by allowing a smaller number of employees to administer a larger
number of applications using fewer servers.
The cost strategy can also be extended to your infrastructure. Although its unlikely that
youll run out of IP addresses, you may have other issues. These days, as servers get smaller
and smaller (e.g., blade servers), electrical power becomes a concern. Ensuring that you have
enough electrical power to supply your servers has become more of an issue in many data
centers. Even when youre part of a small company with a single rack at a co-location facility
or in the back closet, if you continue to add servers, at some point youll start to run short of
electrical power. Adding power lines can be a small expense or a large one, depending on your
situation, but its never a request that you should make. If you begin to consolidate your servers as you upgrade existing servers or look to install new applications, you can dramatically
lower your power requirements.
An even more critical component than power in many environments is the cooling capacity in your data center. Most data centers designed in the past 10 years were created with the
expectation that 20 amps of power and 5 to 10 servers would be placed in each rack. Today,
with smaller servers, a single rack can draw more than 40 amps and contain dozens of servers,
throwing off more heat than can be removed by existing cooling systems. Large installations
are turning to liquid cooling in some cases, and rack vendors are even building liquid cooling
into their rack enclosures.
The addition of cooling capacity is a double request to a companys finances. Not only must additional cooling equipment be purchased and installed (an expensive proposition), but this equipment also requires power, adding strain to your power infrastructure. And if youre forced to move
to liquid cooling from air cooling, then a major capital investment is required. Again, consolidating servers can eliminate the need for your organization to invest in additional cooling systems.
These last two expenses, power and cooling, are soft costs. Its unlikely that adding one additional SQL Server will force you to spend money, but at some point the company will need
to expend hard cash on one of these projects. Consolidation allows you to delay, or even
eliminate, the need for any of these soft costs to become hard costs.
CONSIDERING SECURITY
One very good reason for consolidation is security. Setting up and maintaining a secure enterprise is difficult, and the fewer systems you have to secure, the more secure the enterprise
should be. Security experts talk about the surface area of attack, or the number of points at
which your security can be breached. Each new system means another chance for an attacker
to exploit a forgotten configuration, an unpatched vulnerability, or extra accounts that were
created and forgotten.
If you have one SQL Server, then you have one sa login account to worry about. When you
change the password, as you often should, then youve increased your level of security. If you
have five SQL Servers, there is a chance that one password will be forgotten or not changed
when it should be. You also have five potential sa login accounts that an attacker can look to
exploit. Just as having five doors to your building is less secure than having one or two, more
servers lower your overall security by increasing the surface area for attack. They also increase
the chances that one will remain unpatched or be incorrectly configured.
62 | Lesson 3
area, including setup, installation, maintenance plans, naming, and more, will be carried out
consistently. Each new server and person to be handled by the enterprise increases the chance
that standards wont be met properly. The deviations may be deliberate or accidental, but each
one is a potential problem area. Moving to fewer consolidated environments allows fewer
resources to be devoted to managing these systems and increases the likelihood that each
resource better understands the systems.
TAKE NOTE
You can always look to separate your SQL Server databases on separate servers if performance problems become severe. For some reason, this is an easier decision to make in a
business than the later consolidation decision.
64 | Lesson 3
embark on a plan. Employees are often a companys most valuable resource, especially in the
line of business.
Cost is usually a driving factor in deciding to consolidate servers, but sometimes the cost
savings doesnt outweigh the cost outlay. Because a consolidation effort usually requires new
equipment to be purchased, the cost of a new server may not be worth the investment.
Suppose a company sized a new eight-CPU processor for its consolidation efforts that costs
$50,000. This cost might not be worth the investment to embark on this strategy. This is
often apparent when a single server becomes disk constrained. Although todays disk capacities are growing, there is still a limit to how much space a single server can support through
direct attached storage. If you exceed this capacity and are forced to consider Storage Area
Network (SAN) based solutions, the initial investment can be high. It may be high enough
that you determine a consolidation strategy isnt worth pursuing.
Another area that works against consolidation is the risk factor. This factor encompasses cost,
performance, and staff. If you consolidate your servers onto one Windows machine, youre
in essence putting all your eggs in one basket. If a problem occurs with that one machine
overheated CPU, power supply failure, and so onthen all your applications fail. For some
companies, this is a huge problem. Suppose a company does a brisk business on its Web site
for one of its products. If a problem occurs in the Accounting application, the Web is currently unaffected and the financial department works from paper until the system is fixed.
However, if you put both of these databases on the same server, then an issue that occurs
from an Accounting system upgrade could potentially take down the Web site. Some companies consider this an unacceptable risk, so consolidation wouldnt be a possibility.
If you recognize these risks, you can mitigate many of them by implementing high-availability
features like clustering and redundant hardware. However, these features usually dramatically
raise the cost of the solution in two ways. First are the hardware and software costs from your
vendors for the resources to support these solutions. The other cost is in staffing, because you
may need to pay for training existing employees or hire others to handle these more complex
solutions. Just as the cost of purchasing a larger server can outweigh the benefits, so the cost
to mitigate risks can work against a consolidation strategy.
The last factor you should consider in reasons not to consolidate is the sunk cost factor.
Your existing servers, whether purchased or leased, have a cost already associated with them
that you may not be able to recoup. In some cases, you can trade in old servers on a lease or
sell them back to the vendor. However, if you cant recoup any costs, chances are that these
servers are older and may not be suitable for redeployment in your enterprise. In that case,
the accountants may not see any cost benefits in moving to new servers when the old ones are
paid for and unused. Be aware of this potential roadblock when designing your strategy.
T YPE
OF
R EASON
GOAL
Technical
Technical
Business
Business
The goals you develop should include the type of consolidation youll undertake. You could
consolidate the resources of your SQL Server instances in a variety of ways, and you could
choose to implement any or all of the following types of consolidation:
Instance consolidation. In this case, you look to reduce the number of instances by
moving databases from disparate instances to a single instance of SQL Server.
Physical server consolidation. In this type of consolidation, separate physical SQL
Server instances on different Windows servers are consolidated to one Windows server.
This could involve moving to multiple instances of SQL Server on one Windows server,
or possibly keeping the same number of instances. This could also mean running separate installations on one server by creating multiple virtual servers. The goal is to
reduce both the number of physical servers and Windowsservers that must be managed.
Geographic consolidation. Although this type of consolidation involves moving servers
from one physical location to another, it often includes one of the two previous types of
consolidation. More than any other type of consolidation, this has a larger impact on the
network, so carefully consider that in your plans.
Storage consolidation. Less a SQL Server move than a Windows consolidation, this
involves moving multiple SQL Server instances (and their corresponding Windows
servers) to the same storage device, such as a SAN device. It could also be a consolidation
of your SQL Server database files from multiple drives to fewer. Either option would
require less work by itself than the other methods, but it could be a part of a larger
consolidation project.
In developing the goals for the project, consider the existing environments that the applications run under. For example, many applications have a service-level agreement (SLA) with
end users that cant be easily altered. These should be listed as goals for those systems to
which they apply.
Many other items apply to your systems, such as changes to headcount, budget restrictions
for new hardware, technology changes, and more. As planning is not edition specific, sample
issues to consider are available in the Planning for Consolidation with Microsoft SQL Server
2000 white paper, available at
http://www.microsoft.com/technet/prodtechnol/sql/2000/plan/sql2kcon.mspx.
66 | Lesson 3
SQL Server 2005 is a great platform that has greatly enhanced its database performance over
SQL Server 2000. Youll most likely want to acquire new hardware for your consolidated
server, but not necessarily. In either case, SQL Server 2005 outperforms SQL Server 2000 on
the same hardware, assuming the minimum hardware and software requirements are met.
CERTIFICATION READY?
You set a performance
goal of user response
to data requests at
8 seconds or less. What
factors lengthen or shorten
this user experience?
At each stage, as you gather information about your current environment, note any potential
problem areas. These could be organizational issues, such as the scheduling of downtime, or
they could be technical issues, such as object name collisions. This phase is concerned with
the accumulation of documentation on your environment, not the decisions of whether each
individual change is possible.
ANALYZING APPLICATIONS
The first step in considering consolidation is to examine your applications and determine
which ones will run on either SQL Server 2005 or SQL Server 2008. If a software vendor
wont support your application on SQL Server 2005 or Server 2008, then you should eliminate that application from your plan. SQL Server 2005 should be completely backward compatible with SQL Server 2000 databases, and you can set the compatibility level at 8 (for SQL
Server 2000 as opposed to 10 for SQL Server 2008, 9 for SQL Server 2005, or 7 for SQL
Server 7). However, some vendors wont provide support for this configuration. Make sure
you check, because running applications without support is a good way to irreparably damage
your reputation.
While youre checking this, note that there is no longer a SQL Server 6.5 compatibility
level. If youre still running version 6.5, which is no longer supported by Microsoft, then
you should find out if you can upgrade the application. Substantial keyword and structural
changes occurred between versions 6.5 and 7 and your application may not even upgrade
without a rewrite.
After youre sure all your applications will be supported, you should list the potential applications and their database names and servers. Doing so will give you a master list from which to
start considering consolidations. Take this list, and look for any database name collisions: two
applications that use the same database name. Consider development and Quality Assurance
(QA) databases. Because each SQL Server instance requires unique database names, if you
find two applications that share the same database name, you need to note that fact. They
cant run in the same SQL Server instance, although they could inhabit two separate instances
on the same Windows server. You should also determine whether either applications database
name could be changed.
Dont cross off any names at this point, but knowing how many collisions exist will give you a
minimum number of servers or instances. Suppose your company had three Sales databases
one each for development, QA, and production systemsand the names couldnt be changed.
You would need at least three servers or three instances in a consolidated environment.
The next step is to examine each application and determine whether any of them are mission critical or too risky to combine with other systems. Doing so will further increase your
minimum server number because you may not be able to combine some databases with others.
Be careful, and ensure that you solicit feedback from the business owners of systems. You
may not think the Sales system needs to be separate from the Accounting application, but the
Finance department may feel differently. You can provide them with the benefits and the reasons
you think this combination will work, but make sure you consider the viewpoints of the
various departments.
While you do this, dont mention the multi-instance nature of SQL Server as a way of combining different SQL Server instances onto one Windows server. This is a technical distinction that few business users will understand. Treat instances as if they were separate servers,
and find out what the various stakeholders think about their application being combined with
others. You can make the multi-instance decision later.
Also weigh the security risks and get your security department involved (if you have one).
Many view the development systems as less critical than, say, the Accounting system. However,
that doesnt mean you can put the Development database on the same server as the Web site
backend. Security is a constant process, not a single event, and this is a good place to consider
the implications of combining databases on one server.
Save examining performance implications or hardware requirements for later; the previous
items can quickly lower the number of applications that you must examine in detail. Because
time is precious and the performance and hardware analysis will require more time, you dont
want to examine any more systems than you have to.
Also consider the Service Pack/Patch implications of combining servers. Because many patches apply to an entire SQL Server, or to all instances on a server, you need to be aware that if
you patch one application, youre potentially patching them allor breaking them all, if the
patch changes functionality. Include the third-party vendors past patch response times and
the Service Pack certifications on their applications. Also note whether servers are currently at
different patch levels, and be sure each application is tested at the highest patch level that will
exist on a consolidated server.
MONITORING APPLICATIONS
Once you have a list of applications and their databases that are potentially available for consolidation, you need to begin looking at their performance requirements as well as detailing
information. Because applications that are combined on one server or one instance may affect
each other, you need to examine a few performance points with each application/database
combination.
TAKE NOTE
You should have current baselines for all your servers that you can use in this section. If
you dont, consider gathering these on a regular basis.
You should have up-to-date documentation on the configuration of each server regarding
memory, security, server and database settings, collations, and any other changes made to
a default installation. The disk usage for the server, local or SAN based, as well as network
requirements should be included.
TAKE NOTE
When gathering disk requirements, account for disk space used by files outside SQL
Server. This includes backup files, data-transfer or bulk load files, Data Transformation
Services (DTS) files, and more, that take up space but arent usually associated with
SQL Server.
When youre gathering security requirements, its important to consider whether the
SQL Server instances are all in the same domain. Large enterprises sometimes have more
than one Active Directory (AD) domain. The security changes can be challenging if you
attempt to consolidate SQL Server instances from two different domains.
68 | Lesson 3
TAKE NOTE
You may want to start by gathering quick averages of performance times for queries on the
different servers. You should examine a representative sample of queries using Profiler or
another monitoring tool and gather data on the time and frequency of queries. This is less for
planning than for a contingency plan in case issues arise. Having this data will help you determine in more detail where issues are occurring. When you gather this data, use a few different
dates and times.
Before you begin, start a spreadsheet on which to record the data. Doing so will help you
tabulate and compare your data. List the applications down the left side; next to each, include
the current server, database name, and database size. Use a consistent notation for size (probably gigabytes). You should also note the CPU type and speed, the RAM, and the total disk
space for each server available for the SQL Server instances. At the top of each column, record
a header that notes the values youre placing below it. You may want to check whether SQL
dynamically manages memory or if there is a limit. Record the average that SQL uses as well
as the Windows machine total.
On each SQL Server, you need to examine some counters and determine how much load
each application places on its SQL Server. Gather the following counters in Performance
Monitor to get an idea of each servers usage. Each is discussed in the appropriate section,
and Lesson 1 contains more information about how to gather this information.
MONITORING MEMORY
Memory is critical in SQL Servers processing of requests, and more is always better. Note the
amount of physical memory on the server; then, to properly size a server holding more than
one application, monitor the following counters:
Memory: Available Bytes. This is a good general counter that gives you an idea of how
much memory pressure the server is experiencing. If this is less than 100 MB, the server
is starting to feel pressure.
Process: Private Bytes: sqlservr process. This should be close to the size of Process:
Working Set: sqlservr process if there is no memory pressure from the Windows server.
Memory: Paging File: %Usage. If this value is high, then you may need to increase the
size of the paging file or account for a larger file on the new server.
SQL Server: Buffer Manager: Buffer Cache Hit Ratio. If this is less than 80 percent
on a regular basis, not enough memory has been allocated to this instance.
SQL Server: Buffer Manager: Stolen Pages and Reserved Pages. The sum of these two
values divided by 100 should tell you how much to set in MB.
SQL Server: Memory Manager: Total Server Memory (KB) and Target Server Memory.
The first counter shows how much memory the server is consuming, and the second is the
amount it would like to consume. These values should be close to one another.
These metrics tell you how much memory is being used by the processes inside SQL Server.
Because SQL Server is fairly memory hungry, these will be padded if each application has its
own SQL Server, but you can still use the information to make some guesses about a consolidated server.
Its important to check whether Address Windowing Extensions (AWE) or Physical Address
Extensions (PAE) is being used. If these switches are being used, then you should be especially
careful when consolidating other applications using the same switches onto a server without
large amounts of memory. These extension settings only apply to 32-bit versions of Windows
Server. Large memory usage with these two extensions may push you to investigate 64-bit
versions of Windows Server and SQL Server. Note that the counters for performance monitor dont include AWE values. Youll need to investigate inside SQL Server for more accurate
information. You can get detailed instructions for checking memory in the Troubleshooting
Performance Problems in SQL Server 2005 white paper available at
www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx.
TAKE NOTE
If youre measuring the performance of a RAID set of disks, you need to perform additional
calculations on the values from Performance Monitor. Check one of the white papers on
performance for more details.
All your SQL Server databases should use disk subsystems that include some sort of RAID
protection. But its something you need to note when gathering information about your
servers. Different RAID levels, as well as different numbers of disks in a RAID array, will
affect the performance of your new consolidated drive. Note how many spindles are being
used in addition to the RAID level of each drive being used for database files. This will
help you determine whether your existing subsystem or new design is adequate for the
expected load.
REF
One interesting note on disk performance is that the percentage of disk usage can affect the
performance of your systems. Studies done on disk access times show that performance is
highest when the utilization of the disk is less than 50 percent. After this point, the heads
must wait longer to access data, because more of the data is written toward the outside of
the disk.
70 | Lesson 3
In addition to checking the performance of the subsystem, ensure that you have adequate
space. In consolidating servers, be sure to account for the expected growth of the underlying
systems. Running out of space a few weeks or months after consolidation will likely upset a
great many people, not the least of which is the group that must fund additional space. Make
sure that any new disks on which databases are to be moved can handle the expected growth
for at least six months and preferably a year.
System databases also can experience growth, and that should figure into your calculations.
The master database is fairly small and should remain so in almost all cases, but msdb stores a
few pieces of information that can add to storage requirements. With multiserver administration features enabled, msdb could grow unexpectedlybe sure to note any issues at this stage
in your documentation.
Of more concern than msdb is tempdb because its more likely to have larger storage requirements. Intermediate worktables and other structures are stored in tempdb and can cause
growth in this database that exceeds the size of user databases in some cases. Factor the
tempdb usage on all servers being consolidated, and expect that you may wish to size a new
tempdb using the sum of the other maximum usages. The tempdb database is often placed
on its own disk array, so your calculations for this disk subsystem should ensure a fast and
responsive array for this database as well as adequate space. Expect that the combined load of
multiple systems will be larger on a consolidated tempdb, because this is a shared resource on
each instance.
TAKE NOTE
One way to mitigate tempdb contention in consolidation is to use multiple instances of SQL
Server on one Windows server. Each will have its own tempdb, which means less contention
on one database. The downside is that you may need more disk subsystems to ensure separation. Also balance the gains in tempdb separation with the fixed-memory setups common with
multiple instances.
Consider the space requirements of your data and log backups, as well. Many SQL Server
instances store these files on a separate drive from the data and log files, so make sure that
theyre noted in your documentation.
In Exercise 3.1, youll gather a number of performance-related metrics from one of your SQL
Server instances. Although the exercise will walk you through setting up a single monitoring
session, its recommended that you perform this multiple times at different times on different
days to get a picture of your SQL Server over time.
TAKE NOTE
TAKE NOTE
SLAs arent always easy to find. Usually, these agreements are worked out between departments
in large companies, and the documentation may not be stored with the technical documentation on the server. With staff turnover, its possible that they may even be lost or unavailable,
existing only in the memory of long-term employees.
A good place to start looking for SLA documentation is with a business liaison for a particular
application or with an assistant close to your CIO/CTO. They often maintain this type of
business documentation.
72 | Lesson 3
Your network is a dynamic topology that responds and reacts to changes constantly. Although
switches have helped to smooth out local traffic, routers can seriously affect the performance
of an application if introduced into the flow of traffic. Moving a server to a new physical
location can cause stress on the network if the link back to the users is less capable or reliable
than the previous one. Consider the impact of any move on network traffic and addressing
and consult your network engineers.
TAKE NOTE
You dont have to move a server to a new building to have network issues in a consolidation
effort. Even moving your database to another server in the same rack could result in a subnet
change. Because the use of two or more subnets causes the introduction of a router, you may
have traffic problems, security problems, and so on. Consider the need to involve network personnel in any consolidation effort.
TAKE NOTE
As you document interactions and connections between servers, applications, and processes,
dont forget to document a connection on both servers. A connection between Server A and
Server B should be documented in two places: the Server A documentation and the Server B
documentation.
Included in the discussion of linked systems are two SQL Server topics: replication and linked
servers. These two technologies are often implemented for very different reasons, and combining two servers connected with either of these deserves consideration. Replication is often used
to copy data to another system for two reasons: offline access, which isnt a consideration here;
and reducing the load on a primary system and letting another server have this data available
to an application. If you combine two SQL Server instances that replicate data between themselves, you will probably be defeating the purpose of replication. Carefully examine the implication of such a move, and factor that into your decision to consolidate servers.
Linked servers, on the other hand, often are used to combine information from two servers
in an ad hoc manner. Linked-server queries are often slower than cross-database queries, and
you may be able to improve performance by eliminating the linked server if the two databases
using the link are combined. The downside is that programming changes will be necessary to
rewrite views, stored procedures, user-defined functions (UDFs), assemblies, and so on that
use the linked server. Consider all of this as a postconsolidation project to complete later.
One last interconnected set of systems you should consider is your administrative system
especially the backup system. If you have multiple backup systems (a tape drive on each server
or even two larger consolidated systems), make sure your consolidation plan wont overload
one of them. Although the total amount of backup data wont change, the distribution across
systems could overwhelm one of them, especially if youre using local tape systems for your
SQL Server instances. The same is true of monitoring or other administrative software systems if you have multiple installations.
TAKE NOTE
SQL Server 2008 no longer includes the Surface Area Configuration Manager tool. That functionality is now accomplished using the SQL Server Configuration Manager. The functionality
has not changed, just the method of accessing it through the GUI tool.
Phase 2: Planning
THE BOTTOM LINE
The second phase of this process is the planning stage where the servers are designed and the
processes are initially built to move forward.
At this point, a team is working on this project, and the members have overall goals and
guidelines as well as a list of systems to consolidate. In this phase, you do the more detailed
work of determining the makeup of the consolidated environments by determining which
hardware will be used to run the consolidated servers. This is also when basic procedures and
74 | Lesson 3
processes are tested and developed for your environment. This is in contrast to the Envisioning
phase, where you analyze the benefits and costs of consolidation to the entire enterprise.
You begin with analysis, looking at the information from phase 1 and beginning to consider
how to design the new consolidated system. Note that this doesnt necessarily mean buying new hardware. Existing hardware can be used if it meets the requirements developed in
the design of the new server. The initial testing of procedures and processes occurs prior to
detailed development and final testing in the Developing phase.
You should start to have general ideas of which applications can be combined on one server
based mostly on CPU load and disk space. Without adequate disk space available, either
direct attached or available on a SAN, you cant combine the applications. Many decisions
and trade-offs regarding hardware are affected by other factors discussed later. Check your
plan against all these sections and go back through it each time you make a change. This is a
complex process involving many intertwined factors, so a single pass wont be sufficient.
Consider the hardware systems separately and then in the context of the design possibilities.
Different OS versions have different memory maximum limits. These maximums can affect
your decisions to implement new servers because there will be a software cost as well as a
hardware cost to change versions.
WARNING One important
WARNING Beware of
Your design for a new SQL Server that exceeds 2 GB of RAM should also include the
proper settings for AWE and PAE. You can read about these settings in the Windows Server
2003/2008 documentation or SQL Server Books Online.
Once youve set up these groups, examine the memory usage and tempdb usage to refine
your plan. These two areas are hard to examine, and this is where the process becomes more
of an art than a science. One example is the Memory: Pages/sec counter, which is relative
between servers. Its hard to compare it across servers, but based on the amount of memory
on the server available to SQL Server and looking at similar levels of RAM, you should get an
idea how memory hungry your database is. This is deceiving when you look at raw numbers,
because SQL will cache as much as it can and take up more memory than it needs for small
applications. Try to limit the number of high-memory-usage databases on each server. SQL
Server 2005 memory usage is very different from SQL Server 2000.
76 | Lesson 3
The tempdb database is also a concern with consolidating servers. Because each instance
shares one tempdb, if you have two to three applications that make heavy use of tempdb,
then you can overwhelm a server and swamp the disks on which tempdb resides with requests
(or even cause tempdb to grow out of control). SQL Server 2005 offers some additional uses
for tempdb, such as row versioning and online index operations. Sizing the tempdb database
is an art, and familiarity with the behavior of tempdb over time on your SQL Server instances
helps tremendously. You can look at the sizes of tempdb over time and make some extrapolations regarding the needs of multiple databases on a consolidated SQL Server. Allow for some
padding, and size the new tempdb appropriately to handle the needs of all the applications
that will use it. This often means adding together the usages of all tempdb instances that are
being consolidated.
The following sections show a few of the potential options you can consider when designing a
new consolidated server environment.
A few months later, the QA team is testing a new version of one application and finds a bug.
The resolution from the vendor is a patch for SQL Server. When this patch is applied to
the QA server, it causes a problem and results in the server being rebuilt over the next day.
During this time, the Inventory application is unavailable, and the IT team must deal with
unhappy end users.
TAKE NOTE
Its unlikely that a nonproduction server would be consolidated with a production server,
but work performed on one application can affect another. In this case, a clustered situation might have allowed Inventory to run on the failover server while the primary was
being rebuilt.
This example illustrates how a consolidated server can pose a higher risk of instability than
separate servers. If you have two applications, each with a 20 percent chance of bringing
down a server, then combining them means you have a 40 percent chance of the new server
going down due to one of these applications.
Another example is the consolidation of the Accounting and SalesCRM systems onto one
server. In the event that a hardware failure occurs, two groups are unable to work, and a
greater portion of the business is affected than when the two applications were separate.
WARNING When looking at
This brings us to the need for additional high-availability mitigation strategies for a consolidated server. Clustering, log shipping, database mirroring, and other high-availability technologies become more important (and possibly essential) in a consolidated environment. The
resulting cost of implementing them may outweigh the benefits of consolidating onto fewer
servers.
78 | Lesson 3
This may require that you modify your plan and move databases around. As you move databases, make comments in your spreadsheet that gives reasons or restrictions for your decisions. You may, for example, note that the WebPresence database must remain on its own
server for security reasons. That way, as you move things, its easier to keep all the information
and rationales for your decisions in one place.
SIZING HARDWARE
At some point, you may be moving databases and realize that youre exceeding 70 percent
average CPU or discover that youll need more resources in some area. This is when you begin
sizing new hardware, as is usually the case with consolidation. You might consider consolidation when getting ready to purchase new servers, so this is a logical spot to make decisions.
For your CPUs, youll have to depend on benchmarks and educated guesses if youre choosing
CPUs of a type that you dont have in your environment. Consider the relative strengths in
benchmarks of the integer values, because databases primarily move data around (an integer
operation). You may wish to subtract 20 percent as a pad when sizing the CPUs. You may
consider dual-core CPUs as 1.8 or so single-core CPUs. Multiple CPUs and symmetric multiprocessing (SMP) systems should use a benchmark of each additional CPU counting for 75
percent of a full one, due to the overhead of running the SMP system. Consider the relative
performance of different SQL Server versions in your decision.
RAM requirements are almost always easy to decide on: Get as much as you can and then
add more. You cant have too much RAM in a SQL Server, so size as much as you can install
or afford on a new system. If youre moving to a clustered environment, especially an activeactive node system, allow enough RAM for a failover scenario.
Your disk space requirements will require that you go back to your current applications and
get some numbers for your database growth over time. Factor the space required for backups
into this growth number, and add a pad (such as 10 percent). Try to ensure that you have
enough space for a year when sizing disks for your databases. Because budgets are usually
annual, this works well if you need to purchase more disks later.
CERTIFICATION READY?
Can two servers each
with a named instance of
Sales and each using a
database named SalesDB
be combined onto one
server with two instances
of Sales and SalesDB?
If this can be done, how
would users connect?
TAKE NOTE
Security issues. Your jobs, DTS packages, Integration Services packages, or CLR assemblies may require security permissions not set up on the consolidated server. This is the
time to resolve those issues through detailed examination of the logs created during your
testing. Hard-coded or preset passwords may also cause issues. Check connectivity from
all clients and other servers to resolve any issues.
Domain issues. If youre consolidating two servers from different Active Directory
domains, create procedures to either grant cross-domain permissions or otherwise handle
domain related issues. This also applies to different Active Directory forest situations.
Forests consist of domains and a multiple forest situation could be complex.
Migrating DTS packages to Integration Services. This is a more difficult task,
although you can download the DTS runtime, which enables you to run DTS packages
on a SQL Server 2005 server. Look up Upgrading or Migrating Data Transformation
Services in Books Online.
Moving the data is also something you test at this stage, but in limited amounts. You
shouldnt transfer a 100 GB database over and over to resolve issues. Instead, create a new
database and transfer a small subset of data to it. Then, perform your testing using this
smaller database. In some cases, this may be as simple as performing a database transfer using
Integration Services, backup and restore, or the detach/attach methods. In others cases, the
process may be much more complex, involving the development of customized Integration
Services scripts and packages.
You use actual data or a subset for this testing, but dont focus on specific strategies for one
application. You should be developing general procedures to combine multiple SQL Server
instances onto one instance or server. If you learn specific items for one application, make
a note of them separate from your general procedures.
As youre refining your process and procedure, youll note some issues that can affect the consolidation. These may include extended downtime, additional resources needed to complete
the consolidation, application changes, and so on. These risks should be noted in your plan
and used to determine whether you proceed to the next stage of developing the consolidated
solution.
Beware of scope creep at this point. There is always work going on with many SQL Server
databases, and youll be tempted to include some deployments of functionality along with the
consolidation because the application will be down. Avoid this temptation because there will
be issues associated with the consolidation and it will be difficult if not impossible to determine the source of the problems. Is it the consolidation or the enhancements? One example
is given in the following hands-on exercise, but there are many others. For example, pruning
logins, users, and other SQL Server objects should be tackled as a separate project, either
before or after this one.
80 | Lesson 3
Change the client configuration files to reflect the new account and password.
Change the client configuration files to reflect the consolidated server name.
Create the new account, and assign permissions on the existing server.
Create the new account, and assign permissions on the consolidated server.
Add the steps for changing the application account to your consolidation plan.
Add the Accounting application migration steps to your consolidation plan, ignoring
the account changes.
Test the application using the new account.
Solution: This is a bit of a trick question because the idea in a consolidation effort is
to avoid scope creep. The consolidation should focus strictly on moving the application
to a new server without changing its functionality. Moving the connectivity to a new
account is a major change of functionality and should be completed prior to the consolidation testing. This prevents scope creep by changing the application as a project prior
to considering it for consolidation. The steps should be as follows:
1. Create the new account, and assign permissions on the existing server.
2. Change the client configuration files to reflect the new account and password.
3. Test the application using the new account.
4. Add the Accounting application migration steps to your consolidation plan, ignoring
the account changes.
The steps specific to the account changes on the consolidated server are ignored because
once the application is changed to the new account, the steps involved in consolidation
would be the same as with any other accounts that currently exist on the Accounting
SQL Server.
Phase 3: Developing
THE BOTTOM LINE
Now that youre developing a plan, its time to begin real development of the consolidated
solution. This phase of your plan requires the actual hardware or its equivalent, so that you
can begin testing and refining the plans using full-scale prototypes of the databases and
servers. This also involves validation of the decisions, piloting the consolidation, and a reexamination of the plan to ensure that it works as expected.
There may be budget restrictions, but this is the last testing phase where you can alter the
hardware design before going live. This is why its important to get as close as possible to the
expected live setup and load to validate your decisions. Test various memory and disk configurations to determine whether there are ways to improve performance through reconfigurations. Once the system goes live, these changes will be difficult to make.
This stage should work exactly like the full consolidation, just on a smaller scale. Take one set
of databases and migrate them exactly as you plan to do with all your servers. This set should
result in a consolidated server that looks similar to one from your final design. You may combine two databases onto one serveror more, if that is what your plan calls forbut the final
server needs to look like its production design.
You should then use the consolidated server under the same load that it will experience in
a production environment. This can be accomplished through replaying traces or simulated
loads, but whatever method you use needs to be as close as possible to the real-world result
in order to verify that your processes will work as expected. Youre trying to ensure that the
extrapolations you made for the performance of the consolidated server are accurate in terms
of what the final server will experience.
In implementing this proof of concept, you must test all the scripts and steps as well as any
connections from other systems, monitoring and administrative changes, applications and tools,
and so on. This isnt just a SQL Server test, but an entire application environment evaluation,
with special attention paid to metrics (without neglecting the other parts of the system).
This is essentially a dry run of the processes to find and eliminate any problems. You may
require a second proof of concept if you have a large number of issues, or if you decide that
some things cant be fixed and you must mitigate the problem with other solutions. The
examination of this step is crucial to ensuring a successful production deployment.
82 | Lesson 3
Even though this is a live deployment, you need to perform as much testing as you can and
pay increased attention to the consolidated server. This is the first production change youll
make, and the success or failure of this part of the project will affect your companys business.
Everything prior to this step was a test and didnt directly affect the end users. This time, any
mistakes will have a direct impact on the application as its used by the company.
Phase 4: Deploying
THE BOTTOM LINE
The final phase of your consolidation effort is the deployment stage where you move the
servers onto a consolidated effort in line with your plan and stabilize the applications in a
live, production environment.
You now start deploying ! Your plan from the planning phase should have involved scheduling
that determines the order in which applications and databases are consolidated into their new
environment. There may be requirements to complete one consolidation so that hardware can
be freed up and reused in a later consolidation, or its possible that all your changes can be
done in parallel. Based on the experiences in phase 3 of your proof of concept and the pilot,
however, you may choose to reorder the moves to ensure as little disruption as possible to the
business.
Regardless of how well your testing has gone up to this stage, its highly recommended that
you dont perform all your consolidations at once, or even within a short period of time.
Other issues will arise in your organization that you must deal with in addition to any glitches in the consolidation. Allow time to work on issues without forcing large sections of your
schedule to be reworked.
TAKE NOTE
Staffing can be an issue during a consolidation deployment. Unless you can afford additional consulting help, youll be asking the existing staff to work longer, usually late-night,
hours. Scheduling the consolidations too close together will run the risk of overworking
your staff and increasing the likelihood of mistakes. Allow time between the consolidations
to let your staff recover from the additional work.
Any change to a production environment runs the risk of destabilizing the applications on
which end users depend. This not only leads to less efficient use of the applications for the
business, but also frustrates the end users. There will be a point after which youve decided
the consolidation cant be rolled back to the original environment. At this point, you must
develop workarounds or reconfigurations, or implement contingency plans to stabilize the
environment. Some things you may have planned for and some may be completely unexpected, but in either case you must work to ensure that the nontechnical aspects of the consolidation arent forgotten. Let your end users know of your plans, show them youre working
quickly to stabilize things, and apologize for the inconveniences.
S K I L L S U M M A RY
Consolidation is a huge trade-off process between any number of conflicting requirements. It
may involve trading peak performance for efficiency, costs now for costs later, or some other
set of metrics. Whether this is the right decision for your company or situation is something
that must be examined on a case-by-case basis.
The focus of this Lesson was to provide an outline of how to proceed with a consolidation
analysis and deployment if you decide this is the right decision for you. Remember that the
decision to proceed as well as the process of planning, testing, and deployment is often an
iterative process that requires you to examine your decisions and reexamine them again and
again, considering all your options and their implications.
For the certification examination:
Know the issues to be aware of in a consolidation. Know a number of issues that impact a
consolidation project, both technical and nontechnical.
Knowledge Assessment
Case Study
DkRanch Cabinets
dkRanch Cabinets is a small company with 120 employees that builds custom kitchen
cabinets. The company currently has five applications that it uses to run the business,
each requiring a SQL Server.
Planned Changes
The company would like to consolidate down to two SQL Server database servers: one
for the internal applications and development and one for WebPresence. The company
84 | Lesson 3
wants to be sure it can perform the consolidation without purchasing new hardware
and still have a well-performing system.
The new consolidated servers will run SQL Server 2005.
S ERVER
CPU B ASELINE
M EMORY B ASELINE
SalesCRM
16%
1.6 GB
Accounting
18%
800 MB
Inventory
29%
1.2 GB
WebPresence
32%
1.2 GB
Development
24%
1.6 GB
Existing Infrastructure
The current server setup is on Windows Server 2000, and the individual hardware is set
up as shown here:
CPU S
RAM
H ARD -D ISK
S PACE
D ATABASE
S IZE
E MPLOYEE
U SERS
2000 Standard
4 GB
80 GB (RAID 1, 2 drives)
20 GB
Accounting
2000 Standard
2 GB
60 GB
Inventory
2000 Standard
2 GB
40 GB
12
WebPresence
7 Standard (per
CPU)
8 GB
80 GB (RAID 1, 2 drives)
20 GB
2 + anonymous users
Development
2005 Standard
8 GB
12 GB
A PPLICATION
SQL
E DITION
SalesCRM
All the servers listed are of the same hardware model and have interchangeable CPUs,
RAM, and disks.
Each of these servers meets the recommended requirements for SQL Server 2005.
Business Requirements
The servers can be reconfigured to meet the necessary needs, and any leftover hardware
can be redeployed in other areas as other servers are needed elsewhere. If the consolidation isnt performed, other projects will be placed on hold due to budgetary reasons.
Management would like to consolidate servers, but they want a valid business reason for
undertaking this project.
An existing project to upgrade the database servers to SQL Server 2005 was already
approved, with Enterprise Edition upgrades slated for the multiprocessor servers.
The companys current DBA is overloaded with tuning and managing the five servers,
and a second employee is being considered. If the consolidation is performed, this will
be unnecessary.
If a pilot application is to be included with Inventory, the Accounting application
should be used.
Management is behind the consolidation, but disruptions to the WebPresence and
Inventory applications must be minimized during the workweek.
Technical Requirements
The new servers should use no more than 70 percent CPU based on previous baselines.
Any servers that will be redeployed must have at least one CPU, 2 GB of RAM, and 40
GB of disk space. All current servers run RAID, and any redeployed servers must still have
at least two drives to run RAID 1. All the RAID cards can support either RAID 1 or 5.
For the purposes of estimating, each additional CPU above the first counts as one CPU
when calculating loads.
One spare eight-way server with 8 GB of RAM is being returned to the vendor, but its
available for the next two months for testing if needed.
All the applications are developed in-house and can be configured to connect to default
or named instances. The development procedures, however, call for the development
databases to be named the same as their production counterparts.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions:
1. The current server baselines are listed in the case study. Do the CPU measurements
allow for consolidation to two servers?
a. Yes
b. no
2. The current server baselines are listed in the case study. Do the memory measurements
allow for consolidation to two servers?
a. Yes
b. No
3. Which of the following are valid reasons to proceed with the consolidation? (Choose all
that apply.)
a. Lower salary costs
b. Reduced power consumption
c. Standardized hardware
d. Lower upgrade costs
4. The development group has been planning to add an upgrade to the Inventory application to support new products. Because the application is rarely taken offline, they ask to
include this upgrade in the project plan for the consolidation. What should you do?
a. Include the change in your project plan.
b. Include the change in your pilot plan.
c. Do not include the change.
86 | Lesson 3
5. In what order should the following steps be performed for a successful consolidation?
a. Pilot the consolidation using Accounting.
b. Develop a process for migrating the logins from one server to another.
c. Examine the business ROI for performing a consolidation.
d. Form a team for the project.
e. Migrate the remaining applications and stabilize them on the new servers.
6. Testing of your processes on a full-scale load should be performed in which phase?
a. Planning
b. Envisioning
c. Development
d. Deploying
7. The development group has been planning to add an upgrade to the WebPresence application to support new products. Because the application is rarely taken offline, they ask
to include this upgrade in the project plan for the consolidation. What should you do?
a. Include the change in your project plan.
b. Include the change in your pilot plan.
c. Do not include the change.
8. You are proceeding with the consolidation project and need to determine how to set up
the new server. Which configuration should you use to minimize instances?
a. Four named instances, one for each application
b. Three named instances and one default instance, one for each application
c. One default instance and one named instance
d. One default instance
9. You have almost completed your consolidation plan. The Inventory, Accounting, and
SalesCRM applications have been migrated onto the new server. However, when you
add the Development instance, you experience some severe CPU load problems. What
should you do if this is performed late on a Sunday night?
a. Continue into the week and work out any problems.
b. Roll back the Development consolidation and retest your configuration.
10. You are developing an aggressive consolidation plan to complete all server moves in the
current quarter. July 4 falls on the Tuesday after your first planned server move. Four of
your six IT employees have scheduled vacation on that weekend. What should you do?
a. Move the project plan for the first server migration one week ahead to the end of June.
b. Proceed with the plan as scheduled, and ensure the other two employees are well
versed in the process.
c. Move the project plan for the first server migration back one week to the middle of July.
Analyzing and
Designing Security
L ESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Design Active Directory organizational units (OUs) to implement serverlevel security policies.
Foundational
Foundational
Foundational
Foundational
Modify the security design based on the impact of network security policies.
Foundational
Analyze the risk of attacks to the server environment and specify mitigations.
Foundational
KEY TERMS
active directory (AD): The operating systems directory service
that contains references to all
objects on the network. Examples
include printers, fax machines,
user names, user passwords,
domains, organizational units,
computers, etc.
87
88 | Lesson 4
In SQL Server 2000, some key security templates made security cumbersome and resulted
in workarounds that often didnt meet users requirements. As a result, one of the key
design considerations with SQL Server 2005 was an increased level of security for the
server. SQL Server now not only includes more control and capabilities but also makes it
easier for the DBA to administer the security policies for the server.
This Lesson will examine the methods and reasoning behind designing an effective databaselevel security policy for your SQL Server instances.
Before you can develop an effective security policy, you must understand the requirements
that your plan must meet. These include requirements dictated by your business as well
as any regulatory requirements imposed on your business by governmental or regulatory
agencies. Your plan must cover both of these types, and you must resolve any conflicts
between the two based on your situation.
The requirements imposed on your SQL Servers by the business will in all likelihood be easier
to meet (in other words, they will be less restrictive) but will probably be harder to ascertain.
When someone in business decides on a requirement for an application, that requirement
may or may not be documented thoroughly, which can cause you difficulties during planning.
Youll spend much of this part of the design process interviewing executives, business liaisons,
stakeholders in each application, developers, administrators, and anyone else who may know
why an application has a security need.
The regulatory requirements, conversely, should be easy to determine. A business IT liaison
should be able to let you know which governmental regulations apply. Once you know the
applicable laws or codes, you can look them up from the appropriate agencys offices or Web
site and incorporate them into your documentation.
TAKE NOTE
As you gather this information, document it carefully. You may want to segregate the
data by server instance and database for ease of locating it later. Youll use the various
requirements to design the security policy for your SQL Server.
After you gather the requirements from all sources, be sure to document any existing security
settings on your SQL Servers. These may or may not be in conflict with the requirements,
but in designing a security plan, you should consider the current environment. Have
mitigation plans handy for any changes to be sure that the databases remain available and
functional to users.
Before examining how youll use these requirements, you must understand the security scope
in SQL Server.
REF
External Windows
serverlevel security will
be dealt with in Lesson 5
and internal server
instance and database
security in Lesson 6.
In SQL Server, security is applied at various levels, each encompassing a different scope on
which it applies. Security can be applied at the server level, the database level, and the schema
level. This Lesson will examine overall security system design for the entire enterprise.
Figure 4-1 shows the hierarchy of a SQL Server. The highest level is the server instance, which
contains one or more databases. Each database has its own users, which are mapped to server
instance level logins. Database security applies to the database container as well as all objects
within that database. Outside of the SQL Server are the Windows server and enterprise-level
security structures.
SQL Server has a four-part set of security levels: server, database, schema, and object. The
schema level was introduced with SQL Server 2005. A schema is essentially a container of
objects within a database; a single database can include multiple schemas. SQL Server 2000
blended the objects owner and a schema to form a multipart naming system for objects. Thus
dbo. TestTable and Steve. TestTable were two different objects. However, the owner, Steve in
this case, was bound to the objects, and it was cumbersome to remove the user Steve.
90 | Lesson 4
Figure 4-1
SQL Server hierarchy
REF
SQL Server now separates the schema from the owner in the database. As youll see later in
this textbook, this difference allows you to meet the security needs of the application without
imposing a large burden on the database administrator.
SQL Server also has a number of encryption capabilities along with a more granular permissions structure that enables you to meet most any security requirements for your enterprise.
Youll learn about these encryption capabilities in later sections as you develop a database
security plan.
S COPE
C RITERIA
Server level
Anything that references the login to the SQL Server instance or involves
the configuration of the instance. Authentication of an individual or
service is addressed at this level.
Database level
Schema level
Service level
You should classify each requirement as needing attention at one of these levels. The specifics
of these levels are addressed in later Lessons.
Because requirements for security can be general and encompass many different areas, its difficult to provide a comprehensive list that specifies where requirements fall. Table 4-2 gives
a few examples of requirements at the various levels to show how your analysis can classify
sample requirements.
Table 4-2
Sample security requirements
classification
R EQUIREMENT
C LASSIFICATION
Server level
Server level
Service level
Schema level
Schema level
Items that fall at the database or schema level need to be addressed and considered when any
database design changes are made. Your security architecture must be followed during the
fundamental development of objects.
REF
92 | Lesson 4
CERTIFICATION READY?
Be prepared for exam
questions giving you
choices on conflicting
requirements. Pay
attention to stated
objectives and their
importance.
You should make decisions yourself as much as possible; but when youre faced with mandates or directives that conflict with one another, you need to seek resolution from those in
charge of the companyespecially if the decision is made to stray from regulatory guidelines.
Company leaders often have a working relationship with standards bodies or governmental
offices and can adapt the requirements to meet your companys needs.
If youre forced to choose between conflicting requirements yourself, understand the implications of ignoring any particular set of rules. In making your decision, you should meet
all requirements to the greatest extent possible, but understand that governmental regulations usually are more important than corporate or certification ones. Penalties for ignoring
requirements that have been written into law or codified by a governmental office can be
financial woe for your company and may result in incarceration.
If youre choosing between your corporate mandates and the guidelines of a standards body or certification (such as ISO 9000), you should follow your corporate mandates. This is a general guideline; make sure you have the permission of your companys executives to proceed in this manner.
TAKE NOTE
LAB EXERCISE
When you examine the cost of time, include all the people involved. For example, a password change resulting from a security decision to expire passwords results in the use of the
time of at least two people: the person deciding whose password must be changed and the
person making the change.
Other costs, such as increased time for customers or clients to use your system, their desire
or ability to work with your system, or even potential costs for others to integrate with you,
must be estimated by someone in your organization. The sales department may need to examine your requirements and determine the opportunity cost of a decision on the companys
overall ability to generate revenue.
In Exercise 4.1, youll determine the time cost of resetting passwords.
If need be, you can extrapolate this number to other numbers of employees based on the
expected growth or shrinkage of your workforce. For example, what is the cost for 10 people if
the average salary is $40,000? What is the cost for 20 people if the average salary is $40,000?
This cost analysis section of your design is purely subjective, based on the business in which
youre working. Youll need to solicit feedback from others in the business when you make
your calculations and also review your results with them to be sure youre correctly accounting
for the costs of your changes.
BENEFITS
The cost analysis of your security design also has another aspect: the benefits analysis. Each design
decision, from password policy to encryption to the use of roles in your SQL Server, brings a
security benefit to your enterprise. The results may include lower risk of data loss, better marketing material to help sell your product or service, or a time savings that affects an employees job.
When conducting the cost analysis, make sure to consider the benefits and point them out in
your security plan. Too often, security is seen strictly as a cost, without including the benefits
that result from implementing a particular technology or process.
TAKE NOTE
The benefits of a security policy can be hard to quantify. Extra attention paid to security is
frequently used as a marketing tool to showcase companies. Be sure you communicate the
positive aspects of your security plan to the marketing or sales department.
RISK FACTORS
Closely tied to the cost analysis for many items is the risk that some event will occur. For
example, suppose you determine that a SQL Injection attack on your SQL Server will result
in an average loss of $5,000 in time, product, investigation, and so on. However, using
industry data and past experience, you conclude that there is only a 1 percent chance of such
an attack each month.
The analysis for this event needs to calculate $5,000 at a 1 percent risk level, or a $50 per
month average loss. Any benefits or costs associated with preventing this event should be
compared against the $50 per month value rather than $5,000 per month.
Such risk factors can be hard to determine, but your insurance company can most likely help
you. The insurance industry is built on statistical analyses of various events and the probability that they will occur. In most cases, security deals with an event that causes a breach and
results in a loss of money; your enterprises insurance company can help to quantify the actual
risk levels and the cost or benefit you should assign to any given design decision.
SQL Server uses two methods for authenticating logins to the server: Windows authentication
of users using Active Directory (AD) or local Windows users, and SQL Server authentication
using a name and password. Your company may use other methods of authentication, such
as RADIUS, Novells Identity Manager, or other enterprise identity-management software.
These two, however, are the only ones available to SQL Server, and youll need to choose one
or both of them for your integration efforts.
Windows authentication in a domain environment uses Active Directory and works with the
users and groups youve already set up in your Active Directory database. You can add users and
groups as logins for your SQL servers, and the users credentials will automatically be checked
against Active Directory when they attempt to log on; they wont need to reenter their password.
In contrast to Windows authentication, SQL Server authentication stores the login name and password in the servers master database. To log on to the server, users supply the name and password,
94 | Lesson 4
which are matched against the values stored in SQL Server. Each time a user logs on to the server,
he or she must supply a name and password for the connection.
LAB EXERCISE
This type of authentication offers the advantage of tying access to SQL Server directly to an
individual who has accessed other resources on the network. It also simplifies access because
the user doesnt need to remember a separate account and password combination. The underlying AD infrastructure and the client can automatically authenticate the user. This approach
also ensures that Windows password policies are enforced and the user password is periodically changed for all resources.
If you have clients that cant use AD and must authenticate with a name and password, then
youll need to enable SQL Serverauthenticated connections. This method isnt enabled by
default and must be changed for each server during or after installation.
Non-Windows clients or applications using a technology such as Java or Perl that doesnt support the Windows authentication technology will require you to enable SQL Server authentication. This approach adds an administrative overhead of managing a second set of users and
passwords that is separate from your enterprise list of users.
Choosing SQL Server authentication doesnt disable Windows authentication. Your choices
are Windows authentication only or both SQL Server and Windows authentication.
In Exercise 4.2, youll learn how to change an authentication mode.
UNDERSTANDING KERBEROS
Kerberos is an enterprise network authentication technology that uses tickets passed between
servers and clients to authenticate users. It is part of Windows 2000 and newer Active Directory
domains, which use the TCP/IP protocols for network communication. Your SQL Server can use
Kerberos for its users as well if they are authenticated via Windows authentication. However, the
decision to use Kerberos means that all your clients must communicate with SQL Server using
the TCP/IP protocols. Other network protocols exist as well as other directory services such as
Novells Netware. These other environments obviously cannot use Windows authentication.
To use Kerberos, SQL Server must be registered with a Service Principal Name (SPN) in
Active Directory. This ensures that it can be managed within the Active Directory schema.
When the SQL Server service account is configured to use the local system account, the server
will automatically publish the SPN in AD for you. However, a SQL Server best practice is to
change the startup account from local system to a domain user account to better secure the
SQL Server instance. If youre using a domain user account to run the SQL Server service,
then you have to manually create the SPN for the account in Active Directory. This can be
done with the setspn utility program.
If you choose to use Kerberos as an authentication mechanism, coordinate with your network
administrators to be sure your clients can support the protocol and your infrastructure is set
up to implement it.
REF
All administrators for SQL Server should be configured using server-level roles and Active
Directory groups or OUs to group users together by their particular job function. Toward
this end, you should determine the different functions for which your administrators will
be responsible and then create the OUs or groups necessary for those roles, adding your
Windows users into those roles.
SQL Server lets you set the permissions for serverwide administrative functions in a more
granular fashion. Your security design should incorporate the idea of the least privileges necessary for a particular group to perform a particular function. If specific people are responsible
for adding users and logins to your SQL Server, then dont add them to the sysadmin role.
Instead, assign them the securityadmin role, and allow them to perform that function.
Your decisions about administrative security should not impose a large burden on the system
administrators. If one DBA is responsible for the server, then it doesnt make sense to create
four or five Windows groups for different functions. Just assign this person to a group in the
sysadmin role and let them manage the server.
TAKE NOTE
REF
Lesson 6 discusses
application roles.
The recommendation is that the Windows administrators group be removed from the SQL
Server sysadmin group to ensure a separation of duties and limit the ability of non-DBA
administrators to work inside SQL Server. Consider this even in small companies where
one person performs both functions; the second person performing each job may not be
the same individual, and he or she can easily be added to one group without automatically
being a member of both.
96 | Lesson 4
or other requirements for auditing may prevent the use of this feature. For example, in some
financial applications, a user initiates an action, such as trading a security. If this action is set
up in the application to be performed as another user, using the impersonation capabilities
of the EXECUTE AS clause, then the impersonated user will appear to have performed the
action. Because other users could share this capability, it will appear in audit records that the
same SQL Server user performed all trades, and this may violate the requirement of auditing
who actually performed the trade.
Delegation occurs when the SQL Server uses the credentials from the connection to access
other SQL Servers for a distributed query. Again, your security policy should address whether
this is allowed and what type of configuration should be used in implementing this feature.
REF
Network policies and infrastructure can have a substantial impact on your SQL Server
design of security policies and procedures. You should follow a few general policies from
a security standpoint, but many network infrastructure decisions can have a substantial
impact on the security of your database servers. Because SQL Servers tend to contain
important enterprise data, they should be protected in some basic ways. First, each SQL
Serveralong with other important network serversshould be physically protected in a
locked, controlled access room. Your network policy should include this type of mandate.
Make sure this is the case.
This protection of the servers should also extend to the backup systems, whether disk or tape.
A number of security breaches involving database systems have occurred when backup tapes
were compromised. Encryption technology as well as physical protection needs to deal with
any removable media used for backup of your SQL Server data.
In addition to being physically protected, all SQL Servers should be logically protected at
the network level by firewalls. All connections to the server occur through network access,
even those from the local server console, so a firewall helps to ensure that only legitimate
clients are allowed to access the SQL Server. The network infrastructure team should be
aware of all SQL Servers and the access requirements of clients to configure the appropriate
firewall rules.
As you deploy SQL Servers or work with the existing environment to better secure your
instances, youll work closely with the network team in the placement of your instances
within the network. In many cases, youll want to place your SQL Servers in a central
location to ensure quick response times for clients while protecting them to some extent
from unauthorized access. For SQL Servers that provide data to Internet-accessible systems, this often means placing them in a demilitarized zone (DMZ) on the network.
However, you may also place them near other servers that are segregated from desktop
clients on the network.
CERTIFICATION READY?
Suppose that a new
remote corporate
location should have
users access the central
corporate SQL Server that
is behind the corporate
firewall. How could
this work? What might
need to be changed or
specified?
This configuration on the network may also extend to internal routers as your network grows.
Because large networks usually contain a number of subnets, the appropriate traffic should
be blocked or allowed through to SQL Servers based on the need to access that information.
SQL Servers that are used for storing data that isnt accessed by the enterprise, such as those
used for auditing systems, monitoring systems, and so on, should be behind routers or firewalls configured to block random access from clients.
The specific traffic requirements of SQL Server, TCP/IP connections versus named pipes,
Secure Socket Layer (SSL) connections, encrypted traffic, and so on, will require that your
DBAs and the network administrators work closely together to ensure that inappropriate
access doesnt take place and appropriate access is granted.
In addition to the protection of SQL Server, you need to work with the network team on taking advantage of SQL Servers various features. Many of the capabilities of SQL Server require
certain configurations of the network and access beyond port 1433 for clients. Table 4-3 lists
some of the capabilities requiring network interactions.
Table 4-3
SQL Server features requiring
network configuration
R EASON
Named instances
F EATURE
REF
Many businesses want their SQL Servers to be available 24 hours a day, 7 days a week,
every week of the year. SQL Server includes a number of new and enhanced features to
help businesses achieve a highly reliable database server. However, many high-availability
(HA) solutions can impact your security design, because youre essentially spreading the
security of a single system across multiple servers.
You can design a highly available system in a number of ways, and each requires different
security considerations in SQL Server. Table 4-4 lists these technologies and some of the
security ramifications.
98 | Lesson 4
Table 4-4
High-availability security
considerations
HA T ECHNOLOGY
S ECURITY I MPACT
Clustering
Database mirroring
Replication
Log shipping
No matter which HA technology you choose to implement (if any), you need to make sure
your security policy covers the permissions and policies for each of them. Each will have different security requirements, and its easy to forget to properly secure them. Not assigning
tight security to your backup systems can result in vulnerabilities to your business, and assigning very restrictive security policies can result in the failover systems not being available when
they are needed.
Implementing any of these HA technologies means your security policy must account for the
corresponding needs and requirements. Most of these technologies require the existence of an
Active Directory domain in order to achieve the authentication required between the servers.
Your policy should specifically address which ones and how the authentication mechanisms
will be implemented in your enterprise.
REF
However, many threats to your data are malicious in nature. The mainstream press tends to
portray hackers on the Internet as a great threat to your servers, but there are also corporate
hackers who can compromise your specific servers. These may be consultants, competitors,
disgruntled employees, or any other individuals who can physically enter your business or
interact with your employees. Generally, internal threats are greater than external threats.
In either case, security should be a barrier that prevents these individuals from gaining access.
Your security should prevent them from changing or accessing data and, properly designed,
should prevent them from even knowing the data is there.
You need to implement two types of security to mitigate attacks on your server and design at
least one process into your overall security plan. You must design detailed technical security
in setting permissions, assigning roles and rights, and integrating with enterprise and network
systems. You also need to ensure that administrative security policies are in place to prevent
social engineering practices from being successful. Finally, you should ensure that the Surface
Area Configuration Manager tool is run on every installed SQL Server and any vulnerabilities
or warnings that crop up are addressed in your policy.
Technical security is the easy part of this exercise. Network access to the server should be
controlled by properly configured firewalls and routers as well as integration with enterprise
authentication. Password policies, the use of roles for rights, and proper data security designs
will address these technical requirements. Each of these items is addressed in later Lessons in
this book. Proper application design to prevent SQL injection is also important.
Administrative policies for security are much more difficult to enforce and train people to
use. Many of the security compromises that occur in business do so because of socially engineered access. With social engineering, employees are often tricked into trusting an outsider
and granting access or disclosing the details of their account. Social engineering of passwords,
access rights, or any other circumvention of security policy is difficult to guard against.
Employees are naturally trusting of each other, and they have a tendency to shortcut rules to
help other employees. Skilled hackers can use this natural tendency to trick an employee into
giving them access they shouldnt have.
Constant testing of employees adherence to policy and penalties for bending rules is required
to prevent social engineering attacks. Because this is an administrative security policy rather
than one implemented using computer tools, you should consult with your Human Resources
department about what is and isnt allowed as a policy.
You need to be aware of a few different types of attacks and plan for them.
100 | Lesson 4
This SQL code verifies whether the name and password submitted are correct if a row is
returned. Thousands of applications have been built using this technique. The problem
occurs if an attacker submits something like the following in place of the password:
Mypassword; SELECT * FROM users;
In this case, when the variables are substituted into the previous SQL statement, this happens:
SELECT Name FROM Users WHERE Name = Bob AND pwd = Mypassword;
SELECT * FROM Users;
Note that now two statements are executed: the one that is expected and a select to return all
data from the Users table. Depending on the structure of the application, the attacker could
conceivably gain information about all users on the system. Additional code has been injected
into the SQL statement.
This vulnerability mainly comes from building a SQL statement in an application and executing it. The recommendation to use only functions and stored procedures goes a long way toward
preventing SQL Injection attacks by encapsulating the code inside another structure and using
variables in your code instead of building a statement with the strings stored in the variable.
You should develop a policy for all your application development work that seeks to minimize
SQL Injection vulnerabilities by using only precompiled modules and requiring all code to conform to best practices. If possible, you should specify that dynamic or ad hoc SQL not be allowed.
Although such tools havent proven that they work on SQL Server 2005, its possible that
some such tool will be developed. Using a strong password policy that forces changes on a
regular basis can help to thwart this type of attack. You should also set access controls to limit
the ability of regular users to access the syslogins table.
Protecting Backups
In addition to the database server, you need to secure the backup data extracted from
SQL Server in the event of a disaster. Most companies use offsite storage for their backups, whether tapes in a temperature-controlled environment or real-time disk backups in
another location. This data must be protected just as strongly as the production backup,
because it contains a copy of your databases at a point in time. Many news stories in
recent years have described how backup tapes containing sensitive data have been pilfered.
Your policies concerning backups should ensure that access to them, whether on physical
media or on a file system, is limited to those individuals who require this access (usually
system administrators). In addition, with privacy and data security laws being enacted, data
given to developers for testing purposes should be obfuscated in some manner.
The password features for SQL Server backups may prevent their restoration by an attacker;
however, the files themselves have been shown to contain the data in clear text. A third-party
encryption product or the Windows native encryption features for the file system should be
used to prevent anyone from accessing this data if they manage to obtain the files.
Auditing Access
CERTIFICATION READY?
Your Windows OS and
SQL Server maintain
multiple log files. Which
log maintains auditing
data? Can you identify
other logs and their
purposes?
One of the main ways in which you can measure the effectiveness of your security policy
is by examining its effectiveness over time. This requires that you implement auditing that
both tracks changes made to the individual SQL Servers and catches any attempts at inappropriate access.
Just as a database can track changes to data made over time, your security design should
include provisions that track configuration changes; the addition of users, roles, or other
objects; and security changes made on the server. Preferably, you should use automated
methods to track changes, such as data definition language (DDL) triggers, which can provide
a record of security related alterations.
System errors and alerts should be noted as well, because they often indicate when an attack
has taken place or the database server is inappropriately configured. SQL Server Agent can
notify administrators and should be configured to do so when errors are trapped or alerts are
fired. A good policy ensures that important items in your environment are monitored.
Your design also needs to provide some method of tracking unauthorized attempts to access
your SQL Servers. These access attempts can help gauge how much effort is being put into
testing your security. A network-level intrusion detection system (IDS), automated Profiler
traces, or internal SQL Server alerts can be helpful in providing an audit trail.
TAKE NOTE
If you have automated processes or applications that connect without a live user, expired
passwords can cause failed attempts that look like an attack on your server. Auditing will
help you track down these applications and determine whether there is a configuration
issue or a real attack.
102 | Lesson 4
As with all other security design considerations, the costs and benefits should be factored into
your final design and presented to business leaders and executives.
Once youve performed your cost analysis, you need to make recommendations for a security policy at some level. It may be for the entire enterprise or for a single instance of SQL
Server. In either case, your decisions need to be based on your sound judgment that they
meet the necessary requirements (whether regulatory or mandated by the business). Your
recommendations should also balance the desire to meet other requirements with the cost
to the business of implementing them. Choosing to require password changes every day
costs too much for most businesses and wouldnt be a recommendation for a retail chain.
But for a very high security situation, it might be acceptable.
Although youre gathering information from many people throughout this process and may
be sharing your decisions or thoughts about security with them, you need to create a formal
document that lists the specific security recommendations youve decided on. This should be
a complete and final recommendation of how your SQL Server security infrastructure will be
implemented, and it should include the touchpoints with other groups (such as the network
group) along with your requirements for them.
Your document should describe the rationale for your decisions as well as the impact of those
decisions on the various parts of the business. As much of the cost analysis as possible should
be included in this document. The data you supply and the costs, benefits, and risks should
be used by business leaders to determine how to proceed.
TAKE NOTE
Make every effort to present a complete and final document. Business executives and
affected leaders may overrule some sections and want them changed, and you should
incorporate their feedback into your document and resubmit the plan. However, when you
make your submission, it should be complete, not a draft.
Security is a constant process, unlike many other computer functions that can be configured and left alone. Your design should be encompassed in a living document that changes
and flexes according to the changing environments of SQL Server and your enterprise.
In securing your SQL Servers, you may make choices that other departments dont find
acceptable, given the impact on their business area. Have alternatives for them along with
the risks and costs associated with changing your plan. Security is always a balance between
protecting the integrity of and access to your data and enabling the business to function
smoothly.
As a part of your design, you should include a time frame in which the design itself is
reviewed. Doing so ensures that the design evolves over time to meet the changing environment it governs. Typically this review happens every year, but the time frame can be longer or
shorter depending on your particular requirements.
S K I L L S U M M A RY
Developing a comprehensive security plan for SQL Server isnt a quick or easy process. It
depends on the requirements of your particular business, both internal and external. This
Lesson has guided you in the areas that are important and given you ideas for the items you
should consider in a security policy. However, because the requirements of each organization
are unique, its difficult to specifically determine which policies you should implement.
One guiding principal in all your security design is that each role should have the least
amount of privileges required to complete an appropriate task. Its always possible to assign
multiple roles to a specific individual, but by separating these roles into different groups,
you can more easily ensure that your policies are followed and that rights are granted and
revoked as users move in and out of roles. Windows authentication is
preferred for this reason.
Security is an ongoing process. It requires review as well as auditing of both actions and compliance. Your design should specify methods that let you audit the security of your SQL Servers
to be sure they are properly configured and that inappropriate access isnt taking place. Your
design should also specify a time frame in which the plan is reviewed so that it continues to
meet your requirements.
For the certification examination:
Know how to gather security requirements. Understand the different types of requirements and their order of importance.
Understand the various ways network policies impact SQL Server. There are a number of
places that network polices impact the security plan for SQL Server.
Know the implications and benefits of choosing an authentication mechanism. There are
two choices for SQL Server authentication, and you should understand the differences
between them.
Know how to analyze the risk of attack to your SQL Server and mitigate any issues.
Understand the types of attacks, both computer and social engineering based, and
strategies for mitigating them.
Understand how to examine the true costs of your decisions. Each decision has an associated cost and a benefit as well as a risk factor. Know how to include these in your security
design.
Knowledge Assessment
Case Study
Delaneys Simulations
Delaneys Simulations is a company that provides event scenarios to police and military
organizations for training purposes. The events are mocked up at their facility. The
actions of trainees are recorded and evaluated, and the data is stored in a SQL Server
2005 database.
Planned Changes
The company is growing and wants to make the results of the simulations available to
clients on the Internet, but there is some concern over security. The privacy of the trainees as well as the clients must be maintained, and the results must not be disclosed to
104 | Lesson 4
any unauthorized individuals. A new security policy must be designed. The senior DBA,
Dean, at Delaneys Simulations is tasked with developing policies for the database servers.
Existing Infrastructure
Currently, Delaneys Simulations uses SQL Server authenticated logins for the developers as well as the simulation applications. These applications have been in use for some
time, and a former developers account is used for all the connections.
An Active Directory domain is used for employees and servers as a central point of
authentication. There is only one OU currently, but a second one is planned for the
servers that will be exposed to the Internet.
Additional firewalls are planned for the Internet connection and as a way to segregate
the servers used for the Internet from the other internal servers and clients.
All IT personnel have complete access to the development servers. Only a few people
have access to the production servers.
Business Requirements
Although the company expects that the results of all simulations will be available to
clients on the Internet, there is an understanding that privacy and security requirements
may prevent that. Developing a strong security policy is critical to the companys continued success.
Additional time has been allocated to the development team to make changes that will
provide better security. One possible consideration is the deployment of a .NET client
application to all the companys clients and forcing all data access through this client
application. If the security requirements dictate this approach, the project will proceed.
Because the company has a number of government clients, some regulations relating to
industries in the Code of Federal Regulations (CFR) apply to Delaneys Simulations.
These regulations require the auditing of all access to any persons result data as well as
controls placed on who inside Delaneys Simulations can access this data.
Technical Requirements
The new servers will be placed in a separate OU, and specific accounts will be required
for the SSIS transfer of data.
Firewalls will be installed, and only access through specific routes to specific machines
will be allowed. The only exception is the Internet web server.
It has been decided that as many SQL Serverauthenticated accounts as possible need
to be replaced with Windows Integrated logins, because corporate policy dictates that
all access be granted by the AD domain.
Access through the Internet should entail as few permissions as possible and should
provide the best security that the IT group thinks it can provide.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions.
1. The internal development team members insist that they need to have a copy of the
production servers data in their test environment. However, the CFR regulations seem
to prohibit this, because the developers are not a group that needs access to individuals
data. How should the security policy address this request?
a. Set a corporate policy to override the CFR regulation and allow developer access.
b. Prohibit developer access as required by the CFR regulation, and force the developers
to build their own test data.
c. Allow the developers to receive copies of the data from the production server, but
require obfuscation of the individual information to satisfy the CFR regulation.
d. Allow each client to determine whether they see the need to comply with the CFR
regulation.
2. To comply with the companys security requirements, what should be done about the
developers access to their test server?
a. Their Windows logins should be added to the test servers with the same rights as
their old SQL logins, and their SQL logins should be deleted.
b. Their Windows logins should be added to the test servers with the same rights as
their SQL logins.
c. A central application role should be created for all developers.
d. One Windows login should be created for all developers to share.
3. It is decided that the risk of data compromise should be reduced by limiting the rights of
the Internet application to access data. Which of the following would be the best policy
to choose?
a. Set up a Windows account for IIS to use, and grant this account login rights to the
SQL Server and the tables that it needs.
b. Set up a Windows account for IIS to use that can only log on to the SQL Server. Use
an application role that the ASP.NET application can invoke to get rights to individual tables.
c. Hard-code the information for a SQL Server login into the application to use.
4. Company management prefers that only the DBA or the DBAs backup be allowed to
deploy changes to the production environment. What two policy changes should be used
to enforce this?
a. Limit access to the production servers to only those individuals machines using the
firewall.
b. Distribute a memo to all employees outlining who can access the production servers.
c. Disable all network access, and distribute keys to the data center to the individuals
who will access the production servers.
d. Only grant access to the production servers to the appropriate individuals
ActiveDirectory accounts.
5. Because the CFR requirements can be amended every year, what policy should be set in
place?
a. All past implementations are expected to be grandfathered, so nothing should be done.
b. One of the IT employees should be designated to review the CFR requirements each
year and determine whether application changes are needed.
c. The application should be rewritten every year to ensure it complies with the current
regulations.
6. To ensure that the auditing requirements are met, what type of policy should be set up?
a. Develop corporate guidelines that outline how auditing should be built into any
application that accesses the data.
b. Because only one application currently accesses the data, build auditing into the
ASP.NET application.
106 | Lesson 4
c. Require that the database log all accesses, and force queries to use stored procedures.
d. Disable all client accounts by default, and enable them only after clients phone and
confirm they require access that day.
7. To ensure that only the appropriate individuals receive access, what policies should be in
place for the support personnel? (Choose as many as needed.)
a. Passwords may not be given out over the phone. Password resets must be sent to a
registered e-mail address.
b. Firewall changes to allow access from new IPs should be performed only after the
requesters identity and authority are verified.
c. No account information is to be sent in e-mail or given over the phone in response
to a request. An e-mail must be composed from scratch and sent to registered clients
addresses only.
d. Before troubleshooting problems with a client, verify their identity by sending them
an e-mail using the e-mail address on file with Delaneys Simulations.
8. The disaster-recovery plan includes switching the production and development servers if
necessary. How should security policy be handled for these servers?
a. The accounts are preset on the development machine, but they are disabled. Auditing
is set up to ensure they are not enabled without authorization.
b. No accounts are set up. They can be re-created in the event of an emergency.
c. The accounts are set up and ready in case a disaster occurs. Employees are instructed
not to use them.
d. There does not need to be any policy regarding this matter.
9. What type of account should be used to transfer data between the simulation SQL
Server and the web SQL Server for SSIS?
a. The developers account that builds the packages
b. The SQL Server database server service account
c. A dedicated domain account with rights to only those machines and the appropriate
tables
d. The local system account
10. After SQL Server has been installed on all servers, what should be done before allowing
users to access them?
a. Disable the SQL Server Agent.
b. Set up Profiler to run in C2 mode.
c. Turn off SQL Server login access.
d. Run the Surface Area Configuration Manager tool.
Designing Windows
Server-Level Security
L ESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
asymmetric key: In cryptology,
one key, mathematically related
to a second key, is used to encrypt
data while the other decrypts the
data.
certificate: A digital document
(electronic file) provided by a
trusted authority to give assurance of a persons identity; certificates verify a given public key
SQL Server is a software application that runs on top of a Windows operating system
server. This means the security of a SQL Server installation depends to some extent on
the security processes that exist for the Windows server. If the Windows server is compromised, then there is a good chance that some or all of the SQL Server security can be
circumvented.
The previous Lesson looked at an overall security policy for your SQL Server infrastructure.
This Lesson moves to the more granular level of the individual Windows server. Youll learn
how many of the serverwide security parameters of SQL Server are determined and set
globally for each instance.
107
108 | Lesson 5
TAKE NOTE
With SQL Server authentication, the database server can apply password policies to SQL
Server logins. This greatly reduces the effectiveness of a brute force attack on a particular
login, because the password doesnt have to remain the same indefinitely.
With SQL Server, you have two choices for authentication, as discussed in Lesson 4. With
Windows authentication, the password policies set on the Active Directory (AD) domain
govern the individual login; SQL Server is completely removed from managing this part
of security.
The options available for SQL logins, shown in Figure 5-1, can be set when a login is created
or changed later if a login is edited. In this dialog box a SQL Server login is selected, which
requires that a name and password be specified.
Figure 5-1
Password policy options
SQL Server Management Studio lists three options for this login, as described in Table 5-1.
Although one is called Enforce Password Policy, all three are part of the password policy or
rules for server security.
Table 5-1
Password policy options
CERTIFICATION READY?
These checks have
dependencies: If Enforce
Password Policy is not
set, SQL Server does
not enforce the other
two; if Enforce Password
Expiration is not set, SQL
Server does not enforce
the User Must Change
Password at Next Login.
Or, to put it another way,
you cannot select Change
Password unless you also
select the other two.
O PTION
D ESCRIPTION
D EFAULT
Checked by default
Enforce Password
Expiration
Checked by default
The first two options correspond to the same settings on Windows Server 2003 (and newer)
for user accounts. By default, a Windows server in a domain respects the domain policies set
in AD; but in either case, SQL Server follows the policy of the host Windows server.
TAKE NOTE
The domain host server has only one policy. This means that although you set these
options individually for each instance, the amount of time before password expiration is
the same for all instances on a server.
When a password is set or changed, the date is noted in the master.sys.server_principals system view. This view is checked on each login to determine whether the password has expired.
If the password has expired, then users are prompted to enter a new password before they can
continue with their session.
The three password check boxes are related. You can select Enforce Password Policy
only; Enforce Password Policy and Enforce Password Expiration; or Enforce Password
Policy, Enforce Password Expiration, and User Must Change Password at Next Login.
Be aware though that these settings involve password settings on the Windows operating
system.
110 | Lesson 5
TAKE NOTE
An exception to this policy may exist for automated services that require their own
accounts. You should still enforce the policy; but because of issues if these services fail, and
their inability to change their own passwords, the expiration and change requirements may
not be selected. This doesnt mean you should never change those passwordsbut they
must be manually changed.
LAB EXERCISE
In SQL Server 2005, the encryption capabilities have been greatly expanded, and cryptographic functions and features have been introduced throughout the platform. These features
allow the encryption of data using a variety of techniques and algorithms, which enables the
administrator to meet most security needs.
SQL Server 2000 had only one option for native encryption in your database: the one-way
ENCRYPT() function, which generated a one-way hash of a string. This enabled you to
encrypt a value for comparison with another hashed value later, in the same way Windows
encrypts your password.
This encryptions flexibility was limited, however, and data stored in this form couldnt be
decrypted back to the original text. With todays increased functionality, however, deciding
how to deploy encryption and use it in your enterprise requires careful examination of the
level of security you need versus the effort required to meet those needs.
You need to examine a high-level view of how encryption works before delving into the
details and implications of using encryption. When a user needs to read this data, they must
supply some sort of password or certificate that the server uses to decrypt the data back into
readable values. This process is fairly straightforward, but its administration is complex and
should be considered with caution before implementation.
LAB EXERCISE
In Exercise 5.2, youll set up a database master key before you begin looking at the keys
available in SQL Server.
Symmetric keys are the simpler of the two key types and pose much less of a load on the
server during encryption and decryption operations. Theyre called symmetric because the
same key is used for both encryption of plaintext and the decryption of ciphertext. This poses
some security risks, because only one key is needed for the operations and there is no way to
authenticate the other side of the cryptographic transaction. However, this is still fairly strong
encryption and is often used to encrypt the data in a SQL Server column.
SQL Server lets you use the following algorithms in symmetric key encryption:
When you create a symmetric key, you specify the algorithm to be used as well as an
encryption key mechanism. The encryption method can be the database master key, which
means SQL Server can automatically decrypt and open the key for use in encryption or
decryption operations. The default method is Triple DES if a key is secured by a password
instead of the database master key.
TAKE NOTE
SQL Server encryption relies on the Windows operating system to implement individual
types of encryption. In some cases, older versions of Windows may or may not support
newer encryption algorithms that are supported by SQL Server.
112 | Lesson 5
Asymmetric keys differ from symmetric keys because a different key is used for encryption
operations than for decryption operations. Asymmetric keys come in pairs, and each key in
the pair is designated as either public or private. These keys are more complex and require a
larger amount of resources to perform either encryption operation, placing more of a load on
your SQL Server.
The public key is distributed to users or applications, and the private key is used by the server
to encrypt data. Users submit the public key with their queries, and the server can use that
key to decrypt the data. In addition, because the keys are matched as a pair, the server knows
that a particular users public key is matched with the private key, providing the cryptographic
transaction with a level of authenticity.
All asymmetric keys are created using the RSA algorithm with 512, 1,024, or 2,048 bits in
the keys. Certificates are a form of asymmetric key and are discussed in the next section.
Using Certificates
SQL Server allows certificates to be used in encryption operations in addition to keys.
SQL Server conforms to the X.509 standard for certificates that is widely used around
the world. Certificates can be organized in a hierarchy of trust, which ensures that a
particular certificate can be used in encryption operations and also that certificates can
be traced to ensure that the holder of the certificate is a particular entity. In SQL Server,
you can generate your own self-signed certificates or use a certificate from a Certificate
Authority (CA) that is trusted by your enterprise and has signed a certificate.
Certificates are useful when you need to certify that your data is in fact your data. By
encrypting data using the private key for your certificate, a user can use the public certificate
not only to decrypt the data, but also to trace back the certificate to authenticate the server as
belonging to your enterprise. In essence, the certificate provides a digital signature.
Certificates can also be revoked and expired. This can be useful if you need to limit access
to a certain period of time or if you want to ensure periodic reissue of the certificate and
validation of its identity or authorization.
We have already mentioned the first consideration in the earlier discussion of symmetric and
asymmetric keys: Asymmetric keys provide more security but at the cost of slower performance for both encryption and decryption operations than symmetric keys. For this reason,
asymmetric keys generally arent used to encrypt data, but rather are used to encrypt symmetric keys. The symmetric keys are then used to encrypt the data.
This hybrid method of using cryptographic techniques can be confusing, but its widely
deployed. The speed difference can be substantial, so symmetric keys are commonly used to
encrypt all types of messages and other data; then, the symmetric key is secured by a longer,
stronger, asymmetric key. This technique reduces the performance penalty for the stronger
encryption to a minimum.
Another consideration for encrypted data is that once the data in a column is encrypted, it
isnt available to the query processor for use in indexes, joins, sorting operations, grouping
operations, and filtering. This can seriously impact your databases ability to perform efficient
queries. A database that was completely encrypted would be equivalent to a database with no
indexes; it would incur a substantial performance penalty in reading data due to the decryption operations.
If the overhead of the encryption and decryption operations isnt enough of a penalty,
encrypted data also can affect performance in another way: Encrypted data grows in size (often
substantially) and causes fewer rows to be returned with each page in addition to requiring
more disk space for storage and backups. The growth in size is given the following formula:
Size = (FLOOR (8 + D) / BLOCK) + 1) * (BLOCK + BLOCK + 16)
LAB EXERCISE
D is the original data size, and BLOCK is the bit size of the cipher. RC2, DES, Triple DES,
and DESX are 8-bit ciphers, and the rest are 16-bit ciphers. In Exercise 5.3, youll see how
dramatically a piece of data can grow with encryption applied.
A 20-character data element would require 35 bytes57% more spaceif encrypted. For
larger columns, that difference is less, but for small columns, this may require substantial
schema changes.
Because the addition of encryption can affect your server in a number of ways, you should
consider each of these implications when deciding how widely youll deploy this feature in
your applications. In addition to the performance implications, dont forget that the additional overhead for data size can also affect your schema, forcing changes not only in tables,
but also in related code in stored procedures, functions, assemblies, and other parts of your
application.
The next section will look at a few ways you need to use this information in deciding what
amount of encryption to use and how to deploy it.
REF
TAKE NOTE
The policies you develop for encryption will partly be driven by your enterprises overall security policy. The need for encryption to be deployed will be dictated by that policy, whereas
many of the technical details must be determined separately.
When you determine that data from a particular table requires encryption, be sure you limit
the encryption to only those columns that really need it. The time required to encrypt and
decrypt each column of data affects the performance of your server by slowing it down, and
encryption also requires additional disk space. Avoid including primary keys and foreign keys
(columns used for sorting or grouping operations) as encrypted columns, because you pay
a severe performance penalty for any queries that need to perform these operations on
encrypted columns.
If you need to encrypt a column that is functioning as a primary or foreign key, you
should derive a surrogate key and use that instead as the primary or foreign key.
114 | Lesson 5
Managing Keys
You shouldnt choose to implement encryption without thinking about how doing so will
affect your enterprise. Often, DBAs dont have access to the keys, which limits their ability
to help with queries and check data integrity. The key management scheme is often a complex
and difficult undertaking because the security of these keys is critical to ensuring that
unauthorized individuals cant access your data. Deciding which keys are available to which
individuals and how to store these keys is critical to a well-designed encryption scheme.
If your key management scheme is compromised, then you may need to change your keys.
If youre changing the asymmetric keys used to encrypt symmetric keys, this is a simple
processespecially with certificates, which can be revoked. However, if you need to change
the symmetric keys that encrypt your data, you must decrypt the data and then re-encrypt
it with a new key. This endeavor can be resource intensive and time consuming if you have
a large amount of data. This is another reason to limit the amount of encryption that you
choose to deploy in your database.
Choosing Keys
Its recommended that you use a hybrid key scheme, with asymmetric encryption used
to secure the symmetric keys that encrypt the data. The symmetric keys should use the
strongest algorithm you can afford to deploy. This is determined by testing and weighing the performance implications of each algorithm along with any specific requirements
you have from regulatory bodies. For example, your company may be required by law to
implement DES encryption even though RC4_128 might be more secure.
The asymmetric encryption that you choose should follow the same guidelines. Longer keys
containing more bits are preferable to shorter ones, but there can be a severe performance
penalty. Test the keys under load to ensure that your server can handle the additional processing requirements. Certificates can be used instead of plain asymmetric keys, but be sure you
have a mechanism for ensuring their update, revocation, and replacement as necessary. The
details of developing such a policy are beyond the scope of this textbook, but more details are
available in the Windows Server Resource kits and from certificate vendors.
The overall encryption of the server also requires that the service master key and the database
master keys be protected. SQL Server handles the service master key internally as long as
you use the Configuration Manager to change service accounts. The database master keys are
needed whenever you restore a database to a new server. This often occurs in disaster-recovery
scenarios and development areas, so your policy should address how to protect the keys in
these situations as well as make them available when needed.
Finally, SQL Server lets you implement user-level encryption using a passphrase instead of a
key. This mechanism can be tempting, but be carefulforgetting the passphrase means that
data is lost. Avoid this encryption mechanism in your policy if possible.
EKM is implemented by registering the service in SQL Server 2008. This involves creating a
cryptographic provider object at the server instance level and specifying a dll file containing
the software to implement the encryption. The dll file should be supplied by the EKM
product vendor. The cryptographic provider object can then be used in creating both
symmetric and asymmetric keys. The keys are then used like other keys to encrypt or decrypt
objects in SQL Server. EKM can also be used with Transparent Data Encryption (TDE) to
encrypt entire databases although only asymmetric keys can be used for TDE.
REF
Transparent Data
Encryption is explained
further in Lesson 6.
TAKE NOTE
Extensible Key Management is only available in the Enterprise, Developer, and Evaluation
editions of SQL Server 2008.
SQL Server services process database actions. Each service must be started by an authorized
user. Each service must have an owner with appropriate rights and permissions to perform
the tasks assigned. Use SQL Server Configuration Manager to make any changes to SQL
Server services.
SQL Server and its associated parts are software programs that are similar to any other programs
on your computer. A user must log in and start each of these programs in order for them to run.
For a server program such as SQL Server, you dont want to have to log on and start it manually
each time the server is startedespecially if its restarted in the middle of the night!
In order for SQL Server to start automatically, a user account must log on to the host Windows
server and then start running the application. In Windows, this overall scheme represents a service,
and the service account is the account that logs on to the Windows server and starts the program.
Each of these services can have a service account that logs on to start the service and whose
context is used when performing actions for the service. For the service account to have
enough rights for the service to run under its context, each is added to a group created by
the installation program. The groups for each service are shown in Table 5-2 as well. The
InstanceName part of the group name is replaced by the name of that particular instance.
When the SQL Configuration Manager changes a service account, the new account is placed
in the appropriate group for the rights needed to run that service. The former user is also
removed from the group. This ensures that the appropriate rights are granted for each account
as required in accordance with the principle of granting the least rights needed.
116 | Lesson 5
Table 5-2
SQL Server services
S ERVICES
U SER G ROUP
I NSTANCE A WARE ?
SQL Server
Yes
Yes
Analysis Services
Yes
Reporting
Services
Yes
Notification
Services
No
Integration
Services
No
FullText Search
Default: 2005:SQLServer2005MSFTEUser$ComputerName$MSSQLSERVER
Default: 2008: SQLServerFDHostUser$ComputerName$MSSQL10
.MSSQLSERVER
Named: 2005: SQLServer2005MSFTEUser$ComputerName$InstanceName
Named: 2008: SQLServerFDHostUser$ComputerName$MSSQL10.InstanceName
Yes
SQL Server
Browser
No
No
SQL Writer
N/A
No
TAKE NOTE
If you choose to manually change the service account using the Services applet in the Control
Panel or the Manage Computer MMC snap-in, make sure the new account is placed in the
appropriate group. It isnt recommended that you assign individual rights to each user account.
Each of these services is classified as either instance-aware or instance-unaware. If a service is
instance-aware, then separate copies of its executables and supporting files are installed with
each new instance, and its able to run independently of other instances. Services that are
LAB EXERCISE
instance-unaware are installed only once on each Windows host and serve all instances on
that host. (Table 5-2 gives the classification of each service.)
In Exercise 5.4 Part A, youll explore service account groups.
The default choice is to specify a Domain User account under which the SQL Server service
will run. This approach is recommended to ensure that the least amount of privileges is granted
and that you control which permissions this account has. The account you choose should be an
account created specifically for this service and not an account that an actual person will use.
Its also not recommended that you share accounts for different services or servers.
Most Windows operating systems include three built-in accounts under which you can run
the SQL Server services: the Local System, Network Service, and Local Service accounts.
They differ in the following ways:
Local System. This is a highly privileged account that can access most resources on the
local computer. It isnt recommended that you use this account.
Network Service. This account has the same level of access as the Users group on the
local computer. When it accesses network resources, it does so under the context of the
local computer account.
Local Service. This is a built-in account that has the privileges of the local Users group
on the computer. This is the best choice for SQL Server services if you must use a
built-in account. Network resources are accessed with no credentials and a null session.
All other services have their own default and optional accounts, as shown in Table 5-3.
Table 5-3
Service account defaults for SQL Server services
S ERVICE
D EFAULT A CCOUNT
O PTIONAL A CCOUNTS
SQL Server
Domain User
Domain User
Analysis Server
Domain User
Report Server
Domain User
Notification Services
N/A
N/A
Integration Services
FullText Search
Domain User
Network Service
Local System
SQL Writer
Local System
N/A
118 | Lesson 5
TAKE NOTE
When deciding on a service account, you must consider how the service will be used and
under what security parameters your server will run. The recommendations are general guidelines and should be followed unless your environment dictates particular reasons to deviate
from them.
The following sections address the types of account along with the types of situations when
you should use them and reasons for using each.
The general guideline for most services is to use a Domain User account. If your domain
administrators follow the guidelines for granting privileges to domain accounts, the
EVERYONE and other global groups wont have any privileges. The Domain User account
that is used will be granted the appropriate privileges by the SQL Server setup program on
the local machine, both to run as a service and to access files on the local machine.
Additional privileges may be required in the following types of situations and can be granted
to a Domain User account as needed:
The need to access a drive (local or network) to read and/or write files.
The need for heterogeneous queries accessing another data source.
The need to work with replication.
The need to use mail services. For Microsoft Exchange, this is necessary, but other mail
systems (like those used by Database Mail or SQL Agent) may require a Domain User
account as well.
If you need to grant additional rights to this account, its recommended that you create new
groups and grant the rights to those groups with this Domain User included in those groups.
The groups can be local groups for this Windows host or domain-level groups that provide
access to remote machines.
TAKE NOTE
Even though this section specifies Domain User, it could be a local user account on the
local Windows host for a standalone server.
TAKE NOTE
The Local Service built-in account is used for running services on the local machine
with a limited set of privileges. This account has the same rights and privileges as any
authenticated user, which it receives as part of the Users group. As with any well-secured
machine, you should grant few, if any, additional rights to this group.
This account is a good choice for services that dont access any resources outside of their own
services. Because SQL Server setup adds this account to the appropriate group (as shown
earlier in Table 5-2), it receives access to certain folders in order to run properly, but it has no
rights outside of those minimal permissions.
If you have a service that requires access to additional folders beyond those permissions
granted by SQL Server, its recommended that you choose a Domain User account.
CERTIFICATION READY?
Ensure that you
understand the effects of
using an Active Directory
user versus a local user
account.
If youre performing anonymous file transfers, this account works for Integration Services; but
if you must copy files to or from secured folders on your domain, a Domain User account is
recommended. This account works well for the Active Directory Helper, and its recommended that you leave this account set for that service.
The general guideline is to create a user account for all instance-aware services and
Integration Services. In the next section, youll examine how you change to the user account
youve created.
120 | Lesson 5
When you start this tool, it has three main sections, as shown in Figure 5-3: SQL Server 2005
Services, SQL Server 2005 Network Configuration, and SQL Native Client Configuration.
This section will examine only the first section.
Figure 5-3
Using the SQL Server
Configuration Manager
As shown in Figure 5-3, the SQL Server Services section shows the services that are running
on one particular server. In this case, five services are running on this server, with one named
instance:
SQL Server Integration Services. As mentioned, there is only one copy of this service
for each Windows host. Additional instances share this one service.
SQL Server FullText Search. Each instance that has this enabled will have one service
listed here.
SQL Server. This is the main database engine, shown here as an instance named SS2K5.
SQL Server Agent. This is another instance-aware service. In this case, the service is
running for instance SS2K5.
SQL Server Browser. This is one of the instance-unaware services, meaning this is the
only copy of this service regardless of how many instances are installed.
To the right of the service name, a number of pieces of information appear, as shown in
Figure 5-4. These include the status, start mode, service account, process ID, and type. The
status and start mode will be discussed later in this Lesson in the Working with Services
section. The main item youre concerned with here is the service account. In this example,
three different service accounts are in use.
Figure 5-4
Viewing SQL Server services
in Configuration Manager
The default Network Service account is running Integration Services, and SQL Server Agent
for this instance has its own account. SQL Server, FullText Search, and SQL Server Browser
all share the same service account, which isnt recommended.
You can change the service accounts using the Services Control Manager in Control Panel
or Manage Computer, but it isnt recommended that you do this for SQL Server. The
Configuration Manager is specifically designed to ensure that the proper permissions are set
up for any service accounts. This includes the file-level permissions for accessing files and
folders as well as the necessary service-level rights. Table 5-4 shows the service rights needed
for each service.
TAKE NOTE
S ERVICE
S ERVICE R IGHT
SQL Server
Analysis Server
Log on as a service
Report Server
Log on as a service
Integration Services
Notification Services
N/A
FullText Search
Log on as a service
Log on as a service
None
SQL Writer
None
If you manually change the service account, you can easily forget to grant a permission, which
may result in the service not running or not running properly. You may also inadvertently
grant too many rights to the service, which can result in a poorly secured environment.
Because the Configuration Manager is as easy to use as any other tool, you should only use
this tool to change service accounts.
Before you use this tool, however, be sure youve already set up the appropriate user accounts
on your local computer or on the domain. This tool doesnt allow you to create a new
account, only select an existing account.
Be sure you dont select the User Must Change Password at Next Login check box on the
new account. The service has no way of doing this and wont start. The recommendation
is that you also select the Password Never Expires check box to ensure that this service
doesnt stop unexpectedly. This doesnt mean the password should never be changed, only
that it should be manually changed, not forced.
LAB EXERCISE
In Exercise 5.4 Part B, youll change the service account for the FullText Search service.
122 | Lesson 5
Many antivirus software vendors supply two licenses per user so the home office computer
can also be protected against contaminating the enterprise server. In both cases, though,
antivirus software is reactionaryit cant be updated until after an attack has been detected
somewhere in the world. If you happen to have the first server attacked, even your diligent
efforts wont helpyour systems can still be infected. Plan a control strategy should the
unwanted occur.
Many SQL Server instances run unattended and provide a network service to clients, with the
Windows operating system providing a host for SQL Server. In these cases, antivirus software
shouldnt be necessary. However, in some cases Windows provides other software services such
as file serving, e-mail, or some other process, and antivirus software is warranted.
There is no reason SQL Server and an antivirus software application cant exist together, but
you must appropriately configure the antivirus software. For most applications, the default
configuration will cause the SQL Server to perform poorly.
TAKE NOTE
Some companies require antivirus software on all machines. It isnt worth arguing about
this necessity on a dedicated SQL Server. Instead, work with the network administrators to
properly configure the software.
An antivirus program works by hooking into the disk access drivers and validating every
attempt to write to a file. In this way, it prevents a malicious program from altering a file and
writing a virus into the file that will execute or propagate when the file is accessed.
SQL Server requires file accesses whenever it performs an insert, update, delete, or other operation that changes data, which means the antivirus program by default scans the data and log
files for each operation. Because data and log files are often megabytes, gigabytes, or even larger
in size, this can cause the server to halt while the antivirus software completes its scan.
For this reason, its highly recommended that you configure your antivirus software to exclude
the following files:
TAKE NOTE
Some environments
should exclude specific
files only and not whole
directories. Although
this is possible, it may
cause issues with backup
files, which often have
a unique name for each
backup. Try working
with your network
group for an exception
in this case.
Table 5-5
Services default mode
S ERVICE
D EFAULT M ODE
SQL Server
Started
Stopped
Analysis Services
Started
Integration Services
Started
Report Server
Started
Notification Services
N/A
FullText Search
Stopped
Stopped
Stopped
SQL Writer
Stopped
AFTER
S ETUP
Not all of these components are installed by default, and they may not be present on your
systems. If you choose to install them, however, the mode listed in Table 5-5 is the mode they
will be in unless you selected the autostart options in the setup program.
Each services mode should remain stopped unless youre using the service on this server. For
example, the FullText Search service may be installed, and you may plan on using it, but until
you create a full-text index and require its update, dont start this service. If youve installed
services but arent using them, set them to disabled until such time as you have an application
that requires them.
Although you can use the Service Control Manager in the Control Panel for the Windows
host to change modes, its recommended that you use the SQL Server Configuration Manager
for all service changes relating to SQL Server. Regardless of the mode a service is set to, the
administrator can change this mode to one of the following three modes:
WARNING Dont install all
components on servers by default.
Make sure you need Integration
Services, Report Server, or any other
service before installing it. Its a
tenet of the Trustworthy Computing
Initiative that installations should
be secure by default; installing all
components as policy violates this.
Automatic. In this mode, the service account attempts to log on and start the service
when the Windows server boots.
Manual. In this mode, the service account doesnt log on and start the service when
Windows starts; but a start message can be issued to the service, and it will attempt to start.
Disabled. In this mode, the service cant be started with a start message. The administrator of the Windows host needs to change the service to Automatic or Manual.
124 | Lesson 5
LAB EXERCISE
Most services that are being actively used, such as the database server, analysis server, and so
on, should be set to Automatic so theyre available any time the server is running. Services
that you use rarely can be set to Manual or Disabled to prevent them from starting when the
server boots. If you no longer need a particular service on one of your servers, you should set
it to Manual or Disabled and stop it.
In Exercise 5.5, youll disable a service.
Most firewalls in corporate environments have dedicated hardware devices that function as
highly configurable routers with rules specifying the security rules for traffic passing through
them. This must be configured according to your business needs.
However, as the number and variety of threats have proliferated, many operating systems have
started to integrate and run software firewalls alongside other services. Most of the platforms
on which SQL Server runs include a software firewall that needs to be configured to allow
SQL Server to access and be accessed from clients and other servers.
If you have a firewall enabled, then you must make sure the ports used for SQL Server are
open for communication with those clients that need it. For the default instance, this usually
means that ports 1433 and 1434 are open, but named instances choose a port on startup by
default. In order to secure these instances with your firewall, you need to use the SQL Server
Configuration Manager to assign a specific port to these instances for communication with
their clients.
Table 5-6 lists the various services and the ports that they require for communication. For
named instances of these services, you can specify specific ports to be used.
Table 5-6
TCP port numbers used by
services
TAKE NOTE
S ERVICE
P ORT N UMBER
Chosen at startup
Integration Services
2383
Chosen at startup
2382
445
80
Endpoints
Like the services installed on your server, the ports used by the services shouldnt be opened
on a firewall unless theyre being used. Keep open the minimum number of ports required
for the server to meet your needs. For example, if Integration Services is accessed only on the
local server and not across the network, then dont open these ports.
CERTIFICATION READY?
When examining
security, be sure you
grasp the breadth and
depth of this topic. Do
you understand how
authentications, physical
barriers, firewalls,
disaster recovery plans,
business recovery plans,
risk analyses, policies,
enforcement, incident
response plans, and
forensic investigations all
interact?
Every server that you have running in your enterprise should be physically secured from
unauthorized access. There are many ways of enforcing security and protecting your
server through software, but most of these can be circumvented if the server can be
physically accessed or attacked. The local file system security can be bypassed if someone
can boot a server from another source, and this can lead to security-related files or data
files being copied and the data compromised.
SQL Servers are no exception. But because they can be easily set up on many platforms and
are used in testing new solutions, sometimes the servers physical security isnt maintained as
theyre moved to an employees office or cubicle.
If youre storing enterprise data on a SQL Server, the server should be stored in a physically
secure manner. This means behind a locked door with a limited number of people able to
access the machine. Access controls that log and control which individuals can access the
room are preferred; theyre even mandated in some environments.
SQL Servers often have large disk subsystems, so be sure the disks are secured to prevent their
physical theft. Due to the large data sets, tape backup systems are often used. Make sure physical control over these tapes is maintained and they arent allowed to sit on a desk or other
unsecured area where unauthorized people have access to them.
S K I L L S U M M A RY
This Lesson has investigated how to design Windows server-level security. The server-level
policies provide the highest level of security for SQL Server. Your password and encryption
policies should provide the level of security you need, balanced with the performance required
on your server. The services, service account, and firewall policies should be set to the
absolute minimums required for each server. Enabling all services or opening all possible ports
increases the surface area available for attack on your server unnecessarily. Configure and
make available those items only when you need them, and disable them when theyre no
longer needed.
Security is an ongoing process and should evolve as your server changes. Developing policies
and procedures that make the least amount of resources available from a security perspective
will help to ensure that youre protected and that your server functions in an optimum
manner at all times.
For the certification examination:
Understand the SQL Server password policy. You should know the options for password
policies in SQL Server and the impact of each one.
Understand the different SQL Server encryption options. You should know how encryption
is configured at the server level in SQL Server.
Know how to properly configure a service account. SQL Server has different sections that
require service accounts, and you need to know how they should be configured.
Understand how antivirus software interacts with SQL Server. You should be able to
configure antivirus software to coexist with a SQL Server instance.
Know how to enable and disable services. SQL Server consists of multiple services, and
you should understand how and why to enable or disable them.
Understand how server-level firewalls interact with SQL Server. A server-level firewall is a
software service that runs alongside a SQL Server instance. Understand how these interact
and how they should be configured.
126 | Lesson 5
Knowledge Assessment
Case Study
The Ever-Growing Wealth Company
The Ever-Growing Wealth Company manages retirement funds for many people
and is concerned about the security of its data. To ensure that its database servers are
adequately protected, the company decides to review and revamp its security policies.
Planned Changes
The companys management thinks the security policies for its applications must be
strengthened and that encryption needs to be deployed. However, these changes cant
cause problems in the event that disaster-recovery plans must be implemented.
Existing Infrastructure
All these servers are stored in the companys data center, which is a climate-controlled,
converted office in the companys current location. The company would like to move all
its servers to a co-location facility with a dedicated network connection back to the office.
Currently, a tegwc.com domain contains two main organizational units (OU), one for
the internal employees and one for any client accounts.
The two SQL Servers are named instances that use dynamic ports. A firewall protects
the entire network, but all servers exist in a flat Ethernet topology as shown in the Case
Exhibit of this case study.
Business Requirements
The clients of Ever-Growing Wealth expect to be able to access their data at any time
of the day or night. The existing disaster-recovery plan allows system administrators a
five-minute response time to failover the SQL Servers, and this is deemed acceptable.
However, it cant take more time than this to get the application running.
The company expects that regulatory requirements will be enacted soon for all financial
companies, so the strongest encryption possible is preferred, balancing the performance
of the servers. Newer hardware is available to make up for any issues from the implementation of encryption.
Technical Requirements
For the new servers, the company purchased the next generation of hardware to allow
for the additional load of encrypting data. However, complete encryption of all data
using asymmetric keys will likely overload these servers; therefore, the security policy
must work within these hardware constraints.
Each instance has a SQL Server Agent service that performs various functions,
including copying backup files to another server and running business maintenance
jobs that access the mail server.
The existing named instance configuration cant be changed because its mandated by
the disaster-recovery plan.
Network firewalls are set up to protect the internal network, but it has been decided to
also use the built-in Windows firewalls.
The existing applications use SQL Server logins from clients to access data. This
structure cant be changed, but better security can be built into the application to take
advantage of SQL Servers capabilities.
Case Exhibit
Internet
Ethernet
Firewall
Web Server
WebSQL
TradingSQL
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions.
1. The default Windows 2003 password policy has not been changed. Which of the
following passwords would be acceptable for a SQL Server login named BillyBob?
a. Kendall01
b. KityK@t
c. BillyBob2$
d. Barnyard
2. The company will continue to use SQL Server logins for its applications, but it will
reissue passwords to all its clients. Which of the following password options should you
check to meet the business requirements? (Choose as many as needed.)
a. Enforce Password Policy
b. Enforce Password Expiration
c. User Must Change Password at Next Login
d. Require Complex Password
3. You are planning to change the service accounts for the SQL Server 2005 database
instances. To ensure that you meet the business requirements for disaster recovery, which
account should you choose for each SQL Server Agent named instance?
a. Local System
b. Local Service
c. A Domain User
d. Network Service
128 | Lesson 5
4. After installing your SQL Server 2005 server, it appears to be running very slowly.
Investigation reveals that the mandatory antivirus software is scanning your database
files. What should you do?
a. Remove the antivirus software.
b. Disable the antivirus software.
c. Stop the software from scanning the drive where the SQL Server executables are
located.
d. Stop the software from scanning the data and log files.
5. Because the clients for the Ever-Growing Wealth Company renew their contracts for
services annually, you want those clients who do not renew their contracts to have their
access revoked automatically. What type of encryption supports this?
a. Use a DES key to encrypt data, and require it to change every year.
b. Use certificates issued to each client that the application will use to authenticate
users.
c. Use an asymmetric key that you generate and send to clients to install on their
computer with the application.
d. Set a password age of 365 days, and force clients to change their password through
the application when it expires.
6. Based on the information in the case study, how many services will be running on each
active SQL Server instance?
a. 1
b. 3
c. 5
d. 10
7. Which type of encryption is recommended for sensitive data on each server?
a. Shared DES symmetric keys used to secure DES keys that encrypt data
b. Shared Triple DES symmetric keys used to secure DES keys that encrypt data
c. RSA 1024 keys used to secure AES_256 keys that encrypt data
d. Certificates used to secure AES_256 keys that encrypt data
8. How many instances of Integration Services need to be installed on the spare SQL Server
2005 server for disaster recovery if both the WebSQL and TradingSQL servers could
failover at the same time?
a. Zero, and another SQL Server 2005 server is needed
b. One for both instances
c. Twoone for each instance
9. A certificate is which type of security mechanism?
a. Symmetric
b. Asymmetric
10. In developing a strong security infrastructure, you decide to install firewalls to protect
the internal network from the servers as well as an additional firewall that segregates the
external web server and WebSQL SQL Server 2005 server from the other servers. What
other actions should you take? (Choose as many options as needed.)
a. Configure each instance to use a specific TCP/IP port for communicating with
clients.
b. Configure each servers firewall to allow port 1433 (TCP) through.
c. Configure each SQL Server servers firewall to allow a specific TCP port through to
each SQL Server server depending on each database servers TCP/IP configuration.
d. Configure each named instance to use port 1433 (TCP).
L ESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Specify logins.
Foundational
Foundational
Foundational
Foundational
Design a secure job role strategy for the SQL Server Agent Service.
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
data definition language
(DDL): A subset of T-SQL
commands that create, alter, and
delete structural objects such as
tables, users, and indexes in SQL
Server.
data manipulation language
(DML): A subset of T-SQL
commands that manipulate data
within objects in SQL Server.
These are the regular T-SQL
129
130 | Lesson 6
SQL Server runs on top of a Windows operating system host, but it is a full system
inside itself. There are a number of server-level security features that can be configured
and must be properly set up to ensure the entire database service is secure.
In the previous Lesson, you looked at securing SQL Server from the Windows level, the highest
level of security assignment. This Lesson examines many of the server-level SQL Server security
items that affect the entire database server, such as logins, server roles, endpoints, SQL Server
Agent, and .NET assemblies, as well as the high-level principals in the database. The next
Lesson will delve further into the server and examine the security of individual objects.
REF
All the entities that can request resources in SQL Serverin other words, those logins, users,
or processes that can perform queries and make changes to the serverare known as principals. The securables are the resources that the principals can access. In SQL Server, there are
three levels of principals: the Windows level, the SQL Server level, and the database level.
This Lesson looks at logins (the first two levels) as well as users and roles (the third level).
Creating Logins
THE BOTTOM LINE
In order for a user of any sort, including some of the SQL Server components, to access
data or perform a job in the SQL Server, the user must log in to the server.
A login is required to gain access to resources, although the login itself doesnt grant the user
any rights other than the ability to connect to the server. A login is one of the principals in
SQL Server, an entity that can request resources from the server.
REF
Lesson 4 examined
Windows authentication versus SQL Server
authentication.
REF
Lesson 5 examined
how passwords are
treated for SQL Server
authenticated logins.
REF
Just as a user must log in to Windows, either a local machine or a domain, a user must also
log in to SQL Server. Each SQL Server is separate, and they dont share logins, although SQL
Server has the provision to trust another entity with authentication and enable a user to carry
that authentication through to SQL Server. SQL Server uses two types of logins:
Windows-authenticated logins
SQL Serverauthenticated logins
There are two main differences between these logins from the SQL Server administrator point
of view, but the server treats them the same once the user logs in.
The first difference is that SQL Server trusts Windows-authenticated logins in that it
assumes the local machine security system or the Active Directory (AD) domain has authenticated the user. SQL Server accepts the token presented by Windows, and, if this user has
a matching login, no further authentication is performed. Windows authentication allows
a user or a group to be added to SQL Server, which lets an administrator take advantage of
existing Windows groups for security assignment in SQL Server.
The second difference is that SQL Server logins are individual users only; no groups are available
using this type of login. However, SQL Server can take advantage of some of the advantages of
Windows logins by enforcing password policy in some cases.
You can add both types of logins the same way; the only difference is that you must specify a
password for SQL Serverauthenticated logins. Creating a login, however, doesnt grant rights
to a particular database. That requires a user to be mapped to this login.
One special login cant be removed from the server: the SQL Server system administrator,
or sa, login. This login is built into SQL Server and is similar to the Administrator login on
Windows. The sa login is the highest-privileged login, is a member of the sysadmin server role,
and can perform any operation on the server. You can rename this user, but you cant drop
sa; you also cant remove sa from the sysadmin role. The sa login is disabled if SQL Server
Authentication isnt enabled; however, it can also be disabled manually by an administrator.
TAKE NOTE
LAB EXERCISE
The sa user always is assigned SID0x01, regardless of the name. You can see this by querying
master.sys.syslogins.
Exercise 6.1 shows how to add a login; additional options for this login are detailed throughout
this Lesson.
As mentioned previously, creating a login doesnt grant any rights to the actual client other
than the ability to connect to the server. In fact, without a user mapping to the default database, the login will fail. This happens because the login process sets the initial context for the
user to the default database if one isnt specified, and after verifying the login, a user mapping
is required to establish the session.
Before examining the user mapping, the next section looks at the server roles available to
the login.
A role in SQL Server is analogous to a group in Windows. You can grant certain rights to
a role and then add one or more users to the role to receive those rights. SQL Server has
three types of roles: server roles, application roles, and database roles.
This section examines server roles, and subsequent sections will discuss the other roles.
The server roles in SQL Server are fixed in that their rights are predetermined, and you cant
add, change, or delete the roles. Table 6-1 describes the available server roles.
Table 6-1
Server roles in SQL Server
CERTIFICATION READY?
Ensure that you know
the fixed server roles.
Expect at least one exam
question on this topic.
R OLE
D ESCRIPTION
sysadmin
This role grants its members rights to all functions on the server and
defaults to dbo as a user in each database.
serveradmin
This role can change the serverwide configurations of SQL Server and
initiate a shutdown.
setupadmin
This role can work with linked servers (add, configure, and remove).
securityadmin
This role works with logins (add, edit, and drop) as well as grant
server-level permissions (GRANT, REVOKE, and DENY) and works with
database-level permissions. This role can change SQL Server login
passwords.
processadmin
dbcreator
diskadmin
bulkadmin
You can grant the fixed server roles to any login on your server. This includes any groups that
are added as Windows-authenticated logins. Using Windows groups allows you to manage
your security at the Windows level and ensures that you dont have a mismatch between the
Active Directory mappings for your employees and their capabilities in SQL Server.
132 | Lesson 6
Granting a server role to a login should follow the same principles discussed in Lesson 4 of
using the least privileges required for a particular function.
By default, the local Windows Administrators group (BUILTIN\Administrators) is added as
a login and placed in the sysadmin role. This usually means all your Active Directory domain
administrators are SQL Server system administrators by default. This violates the separation
of duties as a best practice and should be changed as soon as youve created a separate system
administrator login.
LAB EXERCISE
In Exercise 6.2, youll add two server roles to the Delaney login you created in Exercise 6.1.
REF
MORE INFORMATION
A database user is a principal that is authorized to access a particular database and exists
in the database public role.
Every login must be mapped to a user to allow it to access a database, including the default
database.
One user, the guest user, is created by default in each database, and its assigned to any login that
doesnt already have a user mapped to it in a database and has the rights of the public role. This
means that by default a user can access any database on your server if the guest user exists in that
database. As a security precaution, you should remove the guest user from all your databases.
You grant users rights to individual objects, and you can include users in roles. The recommendation is that you shouldnt grant any rights to a user and should instead include users
in one or more roles to receive their permissions. This is similar to the recommendation for
rights not being granted to Windows users, only Windows groups, with those users included
in groups for permissions.
You can create users when a login is created or add users later and map them to existing
logins. Because a login requires a user mapping in the default database for the login to
succeed, at least one user is usually created when a login is created. Additional users can be
mapped at a later time. Exercise 6.3 shows how a new user can be created and mapped to the
Delaney login from Exercise 6.1.
Although logins must be mapped to users, the reverse isnt true: Users dont necessarily have
to be mapped to logins. When this is the case, the user may be in one of two states: orphaned
or mapped to an asymmetric key mechanism.
Orphaned users occur usually when a database is restored on a different server from the one on
which it was created. The mapped login may not exist or may have a different SID on the new
server. These users need to be remapped using the sp_change_users_login stored procedure,
which will remap the user to another login or create a corresponding login that is mapped to
the user. You can find more information about sp_change_users_login in Books Online.
When a user is mapped to an asymmetric key mechanism, it can be either an asymmetric key or
a certificate that exists in the database. This mapping takes place when the user is created and a
specific key that already exists is mapped to the user with the CREATE USER statement.
When a user is mapped to a key mechanism, it means that a connection is made using Service
Broker or another service that supports certificates or asymmetric keys. The login is made using
the certificate or key and then mapped through to the user who is mapped to that certificate. All
other security checks are then made on this mapped user just as with any other database user.
TAKE NOTE
Securing Schemas
THE BOTTOM LINE
TAKE NOTE
The four-part naming structure in SQL Server 2005 and 2008 is no longer server.database
.owner.object as it was in SQL Server 2000. Its now server.database.schema.object.
A user seeking to query the Horses table would need to know whether they wanted to query
Tia.Horses or dbo.Horses. A simple select * from Horses by the user Brian would default to
querying the Brian.Horses table and then dbo.Horses if the first one didnt exist. In other
words, each database user had their own implicit schema based on their username.
Although this was a workable method of separating objects into their own namespace, it created problems when users needed to be removed from the database. Because a user cant be
dropped when they own objects, a user who owned a large number of objects would need all
those objects moved to a new owneressentially, a new namespace. This created a tremendous amount of work in a database of any size and required application changes where code
explicitly referenced a particular namespace.
Starting with SQL Server 2005, the schema has been separated from the owner of an object.
Now a schema creates the namespace, and although its owned by a database user, removing
the user merely requires reassigning the schema to a new owner. All the namespaces remain
the same because the schema name doesnt change and the owner has no effect on the security
of the namespace. This is known as user-schema separation.
A schema is essentially a grouping mechanism in a database; allowing a number of objects
to be classified in the schemas namespace makes it easy to assign higher-level permissions to
roles or users by granting them permissions to the schema or making the schema their default
schema. Just as a role lets you group users, the schema lets you group objects.
Every object in the database must belong to a schema. If one isnt specified when the object
is created, the object falls under the default schema of the user creating the object. A schema
can have any valid SQL Server name, but the schema names in a database constitute their
own namespace and must be unique. Often, a client-side application or a portion of one
is used to group a number of objects, tables, views, stored procedures, and so on, into a
single namespace and permissions assigned to that namespace to simplify maintenance.
For example, if the application deals with human resources data as managed by a client
application developed in Access Projects, the schema might universally for that software
program be personnel.
134 | Lesson 6
TAKE NOTE
In large applications, it is common for the application code to have its own authentication
method. In such cases, the use of users and schemas in SQL Server is much less important. In
such cases, the use of Application Roles could be important. Application Roles are discussed
later in this lesson.
The default namespace for a user appears on the user Properties page (shown in Figure 6-1). You
can change this to any schema in the database using this dialog box or the T-SQL ALTER
USER command.
Figure 6-1
User default schema
LAB EXERCISE
Each schema also has an owner who owns it like any other object. Figure 6-1 shows the
check boxes just below the default schema that you can use to specify ownership of schemas
by this user. A role can also own a schema, as shown in Figure 6-1. Because a role can own a
schema, multiple users can own a schema, through role and/or group membership or specific
inclusion, simplifying permissions for that group of objects. Exercise 6.4 walks you through
creating a schema and assigning an owner.
Use roles to define access categories. Then control the permissions using the role container.
Add or remove users, as needed, to accommodate changing employee assignments.
Database roles are the last of our internal security mechanisms for assigning rights to principals and allowing access to securables. You are introduced to the three types of database roles
in this section: fixed database roles, user-defined database roles, and application roles.
You use these roles to group users so you can easily assign permissions to them. Its recommended that permissions not be assigned to individual users, only to roles, just as its recommended in AD to assign ACL permissions to groups instead of individual users. Then, you
can add users to the role to receive the appropriate rights. This approach greatly reduces the
administrative burden when objects and users are added to and removed from the database.
The three types of roles are all used differently.
R OLE
D ESCRIPTION
db_accessadmin
db_backupoperator
db_datareader
This role allows members to read data (SELECT) from all user tables
in the database.
db_datawriter
This role allows members to change data in all user tables (INSERT,
UPDATE, and DELETE). It doesnt imply that you can read data.
db_ddladmin
This role can carry out any data definition language (DDL) statement
in the database.
db_denydatareader
This role is prevented from reading data from all user tables.
db_denydatawriter
db_owner
This role is the highest-level role in the database and can perform
all configuration or management operations in the database. This
includes dropping the database.
db_securityadmin
This role can modify the permissions and roles in the database.
public
This role initially has limited rights to objects in the database, but
its assigned to every user. This role cant be removed. Its a userdefined role in its permissions, but its mentioned here because the
server creates this role.
Because these are fixed roles, they arent suited to securing your individual objects. Instead,
most of these roles are used for administrative functions or widespread access to objects.
The db_datareader and db_datawriter roles are usually granted to developers because they
allow access to all tables. Granting these rights to individual users means they can access all
data in all tables. If you create a new table that you only want a limited number of users to
access, anyone in this role will still have access. For this reason, limit the use of these roles to
nonproduction databases.
Similarly, the db_denydatareader and db_denydatawriter roles have far-reaching effects. These are
good roles in specialized situationsspecifically, auditing and read-only situations, respectively.
The public role is unique in that, although its created by SQL Server, it has no explicit rights
to your objects. This role has limited rights to read system views by default and is assigned
to all users. This assignment cant be removed from any role. However, the administrator can
change the permissions of this role, as discussed in the next section.
LAB EXERCISE
Like server roles, these should be assigned only in accordance with the least privileges needed
for a job function. For example, assigning the db_owner role to a developer who only needs
to run DDL and back up the database is a poor practice.
Exercise 6.5 shows how to add a user to a role.
User-defined roles are similar to database roles in that they allow multiple users to be
added. User-defined roles can own schemas, and they can have permissions assigned to
them. However, these roles arent added when SQL Server is installed; rather, the administrator creates them as needed. These roles are analogous to Windows Active Directory
groups that are used to combine a series of users for easy management of permissions.
136 | Lesson 6
Its recommended as a best practice in SQL Server that rights to securables not be granted to
individual database users but rather be granted to roles. Each role should be granular enough
to provide security to a set of functionality, but not so granular as to require a cumbersome
amount of administration. Most databases have two to five roles, one for each major section
of functionality or group of users that will access the database.
As mentioned in the previous section, the public role is available in every database and is
automatically assigned to every user in the database. Even though this role is created by SQL
Server, the administrator can modify the permissions for this role, just like any user-defined
role. Any permission assigned is granted to every user in the database, just as any specific
denial of access prevents every user from accessing that object. Just as its recommended that
you not grant explicit rights to the Everyone group in your Active Directory domain, its recommended that you not grant rights to this group in a database. Instead, create another role,
and assign the specific rights you require to that role.
The administrator can create any other role he or she chooses in order to assign varying permissions to users. These roles you create must have a unique name in the database that conforms to the SQL Server object-naming rules. You can create thousands of roles, but doing
so isnt practical. Instead, you should seek to create roles that mimic the major job functions
along which you typically divide the users access.
Once you create a role, you can assign permissions to it using the GRANT, REVOKE, and
DENY statements in the same manner that you assign permissions to any user. These statements are discussed in detail in Books Online with examples and syntax elements defined.
The permissions you assign should be the necessary permissions to enable the role to work
with whatever data it needsand no more.
TAKE NOTE
LAB EXERCISE
You shouldnt perform a blanket assignment of permissions. An auditing role doesnt need
INSERT, UPDATE, and DELETE permissions to tables, and they shouldnt be granted
along with SELECT permissions. Grant a role the specific permissions needed to an object
rather than granting all rights.
As with a user, this role can be assigned explicit permissions to perform functions in the
database, such as creating tables, performing a backup, and so on. If you must assign these
permissions and a fixed database role doesnt meet your needs, then you should assign them to
a specific role, with users added to the role. The role can also own schemas, which gives the
members the right to work with objects under those schemas.
Exercise 6.6 walks through creating a role, assigning it to a user, and assigning explicit rights
to two tables.
The application role is created with the CREATE APPLICATION ROLE command, which
requires a role name and a password. This password is how the application role is secured. A
user cant invoke this role without the password, which is usually secured in an application.
This ensures that only that particular application can access these objects.
As with user-defined database roles, the application role can be granted permissions to schemas
and individual objects. You do this in the same ways shown for user-defined database roles. These
rights arent assigned to users, and users arent granted the application role; instead, the password
is used to move a user into the application role. These rights remain in effect until the user
disconnects from SQL Server or unsets the role using the stored procedure sp_unsetapprole.
TAKE NOTE
SQL Server supports the concept of a DDL (data definition language) trigger, which responds
to events that define objects in SQL Server. The primary events are the CREATE, ALTER, and
DROP statements and their variants. Because these statements fundamentally alter the way in
which the server can work with the addition or deletion of objects, a trigger allows auditing or
greater control over these types of changes. The objects affected by DDL statements can be data
objects (tables, views, procedures, and so on) or principal objects (logins, users, roles, and so on).
Triggers have been a part of SQL Server since its inception. Triggers are sections of code that
execute in response to some event. Prior to SQL Server 2005, triggers were limited to data
manipulation language (DML) events. These are INSERT, UPDATE, and DELETE statements that modify or manipulate data.
Just like a DML trigger, which fires when a particular event occurs, a DDL trigger fires when a
DDL event for which its set up occurs. These types of triggers are more complex and use different internal structures to determine what data is available from the event. DDL triggers execute
after the T-SQL statement is complete. These triggers cant be used as INSTEAD OF triggers.
The following sections discuss the scope, events, and recommended policy for DDL triggers.
138 | Lesson 6
to perform any action across the server. A separate DDL trigger for the CREATE USER event
would need to be created in the Sales_Dev database to track events in that database.
Using scope can limit the execution of these triggers to only those events that need to be
acted upon. Often, a database administrator is concerned about events in one database that
arent important in another.
This trigger notes the scope (the Sales table) and the event (INSERT). Multiple events can be
included if necessary.
You can also set a DDL trigger to respond to events, as shown here:
CREATE TRIGGER NoDrop
ON DATABASE
FOR DROP_TABLE
AS
PRINT Disable Trigger NoDrop to drop tables
ROLLBACK
GO
TAKE NOTE
This trigger is scoped for the current database and is fired in response to a DROP TABLE
command, which would fire the DROP_TABLE event. See Books Online for the events that
occur on a SQL Server.
In addition to events, a DDL trigger can also respond to event groups. These are broader classifications of events, such as the DDL_LOGIN_EVENTS group, which covers the CREATE
LOGIN, ALTER LOGIN, and DROP LOGIN events. These groups are linked in a tree, a
portion of which is shown in Figure 6-2. The complete tree is available in Books Online and
is extensive, covering server-level and database-level events.
Using an event group instead of the event class ensures that you dont forget an event related to
that class. Its easier to administer and work with one trigger that tracks all LOGIN events than
it is to create three separate triggers for each of the CREATE, ALTER, and DROP events. Be
aware of the tree structure, however, because lower-level events will cause the trigger to fire. The
code in your trigger must be able to handle all the events in your group to work properly.
WARNING Beware of
encrypting triggers. If the code is
encrypted, the trigger cant be replicated. Also note that DDL triggers
arent fired in response to temporary table operations. This is an
inherent limitation and means you
cant prevent or audit these events
with these triggers. Make sure
all developers and administrators
know that as part of your policy.
The first is the firing order. This can be important, because one trigger may depend on
the other having already executed in order to function as designed. You can change the firing order of your triggers, but this must be done explicitly; and you should ensure that all
instances of multiple triggersDML and DDLhave the firing order set and known.
Second, each trigger consumes resources. Having multiple triggers means more work for the
server to set up the execution environment as well as more potential work in the same transaction. Dont overload the server with unnecessary triggers. If possible, ensure that triggers are
consolidated, perhaps requiring code reviews for multiple-trigger situations.
Another feature of triggers to be aware of is the capability for code encryption. This is discussed in the next section, Defining a Database-Level Encryption Policy.
DDL triggers also require different coding structures to access the data about events. Unlike
DML triggers, which use the inserted and deleted tables, a DDL trigger requires you to work
with event data. Make sure anyone using these triggers has been properly trained to gather
the data.
REF
As has been shown, these triggers are powerful but much more complex than DML triggers. Therefore, you need a more extensive policy to deal with their use in your servers. The
features mentioned should be noted in your policy, but you should also have guidelines indicating where and why these triggers are created. As discussed in Lesson 4, when you look at
designing a security infrastructure, there may be regulatory or industry guidelines about controlling or auditing various types of events, most notably security changes. DDL triggers can
provide a way to do this, but dont overuse the triggers and cause a large burden on the server
or company. For example, preventing new logins may provide some level of security, but if
the administrator cant disable the trigger when needed in a timely fashion, the business may
be negatively affected.
These triggers also need to be monitored for the information they may return or store. This
generally means an auditing environment, so you should have a policy indicating how this
data is secured and made available when needed. Security for the DDL trigger data is as
important as the security of the data used by the company, because it can show whether the
company data is being properly accessed or compromised.
140 | Lesson 6
SQL Server lets you use the WITH ENCRYPTION keywords in the CREATE or ALTER
statement to encrypt the data that makes up this object. This prevents anyone who gets a
copy of the database from reading the T-SQL code that forms the object.
In Lesson 5, you studied an overall encryption scheme and policy for SQL Server using the
encryption mechanisms that turn plain-text data into ciphertext. The keys exist at a server
or database level, and the encryption occurs at a table or column level. As mentioned in that
Lesson, the minimum amount of data should be encrypted. This ensures good performance
of your SQL Server. Your policy should be specified at a corporate level, with exceptions
documented as needed.
TAKE NOTE
REF
GO
ALTER DATABASE mydatabase
SET ENCRYPTION ON;
GO
It is critically important to understand that the database master key and the encryption certificate need to be backed up to a secure location. This location also needs to be separate from
regular backups or other copies of the database files. The encryption security provided by TDE
is meaningless if database files and the certificate both fall into the hands of the wrong person.
Further, for disaster recovery or other restore operations to a different server, the certificate will
be required for restoring a TDE encrypted database. You can think of the certificate as the key
to unlocking your database. Certificates are very rarely changed so securing a backup copy of
critical certificates should be an easy activity.
Securing Endpoints
REF
Lesson 10 discusses
database mirroring.
Every network communication with SQL Server takes place through an endpoint, which
is a communication point for SQL Server. Endpoints exist for the protocols clients use to
communicate with SQL Server as well as for database mirroring, the Simple Object Access
Protocol (SOAP) and Web Service requests, and the Service Broker.
When the server is installed, a Tabular Data Stream (TDS) endpoint is created for each protocol that is enabled. Table 6-3 shows the protocol endpoints and the default names as set up by
SQL Server. Each protocol requires an endpoint with a unique name.
Table 6-3
Default protocol endpoints
P ROTOCOL
Named Pipes
Shared Memory
TSQL LocalMachine
TCP/IP
VIA
The Shared Memory, Named Pipes, and DAC protocols have only one endpoint per instance.
The VIA and TCP/IP protocols have a default, but the administrator can create additional
endpoints for various services.
Each endpoint exists as an object in SQL Server, like many other objects, and permissions
are granted to allow its use. You can apply the typical GRANT, REVOKE, and DENY permission statements to the endpoint using the ALTER, CONNECT, CONTROL, TAKE
OWNERSHIP, and VIEW DEFINITION permissions. Each of these permissions is similar
142 | Lesson 6
to the same object permissions discussed in Lesson 7. The exception here is the CONNECT
permission, which isnt associated with most other types of objects.
Each of these endpoints enables a communication path into SQL Server, but they all function
slightly differently with different options and potential security issues. The following sections
discuss each type of endpoint.
TAKE NOTE
The default permissions to an endpoint allow all users to connect. This permission is implicitly granted to a login when its created. You can change this for the TDS endpoints by
DENYing access to Everyone and then granting explicit permissions to each login that will be
allowed to connect.
Each endpoint can be associated with any IP or one particular IP on the server. Its also associated with a port. When you create a new endpoint, you can specify both of these parameters
to configure how clients will be allowed to connect to the SQL Server. For dynamic ports, the
default TCP endpoint is used. You can create additional TCP/IP listeners in the SQL Server
Configuration Manager, under the Network Configuration section, and then associate them
with an additional endpoint. VIA connections are treated the same as TCP/IP connections.
SOAP allows method calls to be mapped to stored procedures or ad hoc batches to be sent
to the server using the HTTP or HTTPS protocol. Its often used in web services as a way to
programmatically access methods on a remote server.
When an endpoint is created for use with SOAP calls, it must be specified with not only the
port to be used, but also the protocol (HTTP or HTTPS) along with the type of authentication that will be allowed. Five types of authentication are available; theyre listed here from
least secure to most:
TAKE NOTE
An important facet:
Anonymous authentication isnt supported
with endpoints. The
user must be a valid
Windows user.
Basic. One of two mechanisms in the HTTP 1.1 specification. The username and password are encoded in the header using base64 encoding. Requires https communications.
Digest. Second mechanism in the HTTP 1.1 specification. The username and password
are hashed using MD5 and compared on the server. Only domain accounts can be used.
NTLM. Authentication method used in Windows 95, 98, and NT4.
Kerberos. Supported in Windows 2000 and later. A standard authentication mechanism
used by Active Directory and requiring that a service principal name (SPN) be registered
for SQL Server.
Integrated. Allows NTLM or Kerberos methods to be used.
Each of these types has pros and cons, although only one at a time is associated with an endpoint. You can change the authentication type using the ALTER ENDPOINT statement.
Kerberos is preferred, and Basic is the last choice in terms of security.
Each SOAP endpoint also requires a unique path on the Windows server that equates to a
virtual directory in IIS. This isnt necessarily a security issue, although setting standard paths
on all SQL Servers gives potential attackers information they can exploit.
One specific security recommendation for SOAP endpoints is that you should specify only
those methods actively being used as available with this endpoint. If methods are retired, you
should remove them from the endpoint. SOAP endpoints can also support ad hoc batches,
but this capability is disabled by default.
TAKE NOTE
Unlike the other endpoints, however, these endpoints provide a fallback option. The connection can be attempted with either a certificate or Windows method and then fall back to the
other. You specify this along with which type of authentication to use first in the CREATE
ENDPOINT or ALTER ENDPOINT statements.
Its recommended that you not allow the fallback. If you truly need certificate authentication,
then you should specify it and not let it fall back to Windows authentication. Often a backup
connection method becomes permanent because it works and employees wont seek to fix the
primary method. If you allow this to stop communications when it doesnt work, it will force
people to fix the primary method of communication.
One other security mechanism is available for these endpoints: encryption. The connection
used for this endpoint can be set to not use encryption, to allow it if the client is capable,
or to require it in all communications. The default is to require encryption using the RC4
algorithm. The endpoint specifies whether the AES algorithm will be used instead, or if either
algorithm can fall back to the other.
In general, you should require encryption if all clients can support it. If not, then specifying
the SUPPORTED option will allow encryption to be used when possible. Avoid disabling
encryption for the critical services if at all possible, because it means data is being communicated in clear text.
144 | Lesson 6
endpoint isnt being used, it shouldnt be started; but should it be stopped or disabled? The server
responds differently to these two states, and this is important in deciding on security policy. In
the disabled state, the endpoint doesnt respond to client requests, which is the same as if the
endpoint hadnt been created. If an endpoint isnt being used currently, it should be in this state.
In contrast to the disabled state, the stopped state doesnt respond to client requests but returns an
error. This is similar to the 404 errors returned by web servers when a page doesnt exist. This state
doesnt allow clients to connect to the server, but it does tell a client that an endpoint exists on this
port that may be started again. The stopped state is useful for temporary service interruptions, like
maintenance activities being performed on the endpoint; however, you shouldnt use it as anything
more than this. If the endpoint wont be used for any length of time, you should disable it.
Finally, its recommended that you use secure communicationsHTTPS for SOAP endpoints and encryption for Service Broker and database mirroringto make sure your transmissions arent intercepted while in transit. The defaults for the various types of endpoints are
set in accordance with the Trustworthy Computing Principles in mind, requiring Windows
authentication and encryption by default.
The msdb database has three fixed database roles that allow you to assign permissions relating
to SQL Server Agent to users who arent sysadmins.
SQL Server Agent is an extremely useful component in the SQL Server platform, letting you
schedule tasks that need to be performed both in SQL Server and on the domain. In the past
with SQL Server 2000, a broad scope of permissions was required to use the Agent, but starting with SQL Server 2005, a number of roles have been introduced allowing finer-grained
control over the security for this subsystem. You can also specify proxies for jobs instead of a
central proxy for all non-sysadmins as in SQL Server 2000.
As with other security decisions, your policy should grant the least privileges required to
logins in order to allow them to perform their jobs. The three roles are:
SQLAgentUserRole. This is the least privileged role for using the SQL Server Agent. It
allows the user to work with single-server jobs for that instance only and to enumerate operators but not change them. Only jobs owned by the user can be examined and changed. The
job history cant be deleted.
SQLAgentReaderRole. This role includes all the privileges of the SQLAgentUserRole, but
it can also work with multiserver jobs and view their history, properties, and schedules. This
role cant edit those multiserver jobs nor delete job history.
SQLAgentOperatorRole. This role includes all the privileges of the other two roles as well
as the ability to list alerts, operators, and delete the job history from the local server. This role
can also enable or disable jobs.
None of these three roles is as powerful as an administrator, and none can create or edit alerts,
operators, or proxies. However, if youre delegating the ability to start jobs, you should consider using one of these roles to give limited privileges to certain users.
sysadmin should decide to which subsystem(s) the proxy has access. These are the
subsystems:
ActiveX Scripts
Operating System Commands
Replication Distributor
Replication Merge
Replication Queue
Replication Snapshot
Replication Transaction-Log Reader
Analysis Services Command
Analysis Services Query
SSIS Package Execution
Unassigned
As with roles, you should create proxies for different types of jobs or actions that they need
to perform. However, they shouldnt have more permissions than necessary to complete a
particular job step. If a series of steps requires access to Integration Services packages only,
and another series of steps accesses the operating system only, you shouldnt create a proxy
with rights to both systems and use it in both cases. Instead, create two separate proxies.
Your policy for creating proxies should also seek to minimize the rights required for
each job and to share proxies in job steps only insofar as theyre doing the same work as
another job step.
Starting with SQL Server 2005, there has been a huge increase in the capabilities of stored
procedures and functions. This involves the integration of the .NET Common Language
Runtime (CLR) with the database server. This lets you use any .NET language, from C#
to VB.NET to Perl.NET, to write a series of methods that can be wrapped in a function or
stored procedure and called in any T-SQL batch.
The assemblies that can be called from within SQL Server must first be registered in the SQL
Server, similarly to the way you must register DLL code with Windows using the CREATE
ASSEMBLY command. This registration command allows the user to specify how the security
for these assemblies is controlled by the server. There are three levels of security for assemblies:
SAFE, EXTERNAL_ACCESS, and UNSAFE.
Setting SAFE
SAFE assemblies are completely written in managed .NET code and are intended to
access resources only within SQL Server. Computations and business logic can be performed with data in tables, but there is no access outside the SQL Server, including the
Windows host file system and API calls.
This is the most restrictive level of security for a .NET assembly. If requirements dictate that
a .NET assembly perform the computation on only SQL Server data, this is the level of security you should set. There are some restrictions on the assembly, such as the fact that it must
be type-safe and a few other limitations on the programming capabilities allowed.
146 | Lesson 6
If the CREATE ASSEMBLY permission is granted to a user, then that user can create assemblies with this level of security.
Setting EXTERNAL_ACCESS
Assemblies that must access resources outside of SQL Server, such as the Windows host
file system, the network, the local registry, or web services, are usually secured with
EXTERNAL_ACCESS security level. These assemblies are still written as managed code
and must be typesafe, but they can make limited access outside of the SQL Server. These
assemblies can access memory buffers owned by the assembly in the server.
If an assembly requires this level of access, then this is the preferred level of security because
there are still restrictions on the programming of the code. The login creating this assembly,
however, requires the EXTERNAL_ACCESS ASSEMBLY permission in addition to the
CREATE ASSEMBLY permission.
Setting UNSAFE
UNSAFE assemblies are completely unrestricted by SQL Server and can access any resource
on the local machine or the network. These assemblies can access memory buffers in the
SQL Server process space and call unmanaged code, such as legacy COM components.
There are virtually no restrictions on the type of code that can be called from an UNSAFE
assembly, which can severely affect the stability of SQL Server. Because of the potential issues,
only a member of the sysadmin server role can create an UNSAFE assembly.
Its recommended that you require extensive code reviews by very experienced developers
before allowing UNSAFE assemblies on your server.
S K I L L S U M M A RY
Developing security policies at the SQL Server service level is much more complicated in SQL
Server 2005 and 2008 than in previous versions. With a change in the paradigm of how the
server security is structured, the administrator must better understand the new capabilities
and the ramifications of using them.
The login and role structure is similar to previous versions, but changes allow more granular
control of permissions; administrators should study these areas. This is
especially true for the SQL Server Agent permissions and roles.
Some of the new structures, such as DDL triggers, endpoints, and .NET assemblies, mean that
the designer of a security policy must address new areas. Doing so requires extensive work to
understand how these new features work from a security standpoint.
This lesson has broken down SQL Server security to those areas that affect the overall server.
This completes two thirds of the security structure for SQL Server. The next Lesson will discuss
the most granular security, at the object level.
For the certification examination:
Understand the different types of SQL Server logins. You should know different types
of logins available in SQL Server, Windows-authenticated logins, and SQL Server
authenticated logins, as well as their differences.
Understand the server roles available in SQL Server. Know the different server roles,
including their capabilities and their restrictions.
Understand database users. You should understand what a database user is and how its
mapped to other principals or securables.
Understand schema concepts. Know what a schema is and its role in security management.
Understand database roles. Know the three types of roles in SQL Server, understand the
differences, and know when to use them in your security design.
Know how to work with endpoints. Understand what they are and how they impact security.
Understand what DDL triggers are. These triggers are different from regular triggers and
you need to understand what they are and how they work.
Know how to secure SQL Server Agent jobs. The SQL Server Agent subsystem runs alongside the other SQL Server services, and you must understand how this job system impacts
the overall security of the database platform.
Understand how to secure .NET assemblies. You should understand how security works in
regard to .NET assemblies and the implications of the various settings.
Knowledge Assessment
Case Study
Herd of Two
Herd of Two stables is a large facility that boards and trains horses. It exists on 400 acres
in Colorado and employs 12 administrative and technical people to handle its computing infrastructure. In addition, 32 other stable hands have requirements to interact with
terminals to use the time-card system and to track horse care.
Planned Changes
Herd of Two stables is currently running one SQL Server 2000 instance on Windows
2000 for its three applications. It would like to add two additional instances on separate
servers to improve performance and upgrade to SQL Server 2005 at the same time.
All the servers need to be secured properly. The stable hands use SQL Server logins
because they dont have accounts set up in the AD; however, they need to conform to
the password policy present on the domain.
There is also the need to use encryption to protect the personal information of clients
along with their credit-card billing information.
Existing Infrastructure
The current servers are running Windows 2000. There are enough licenses to cover new
servers, so its assumed Windows 2000 will be installed on the new servers.
148 | Lesson 6
The hardware for the new servers as well as the existing server meets the requirements
for SQL Server 2005.
Business Requirements
All employees using SQL Server logins must abide by the password policy, which is set
on each machine using AD Group Policy.
The barn foreman has requested that he be notified whenever a new stable hands login
is added to the SQL Server to be sure they have been trained properly before receiving
access.
Its requested that a high-availability system be set up between two of the servers for the
horse-care system, but no money is available for a clustering solution.
The barn foreman has requested the ability to perform backups of the horse-care database during the afternoon when all horses have received their medication.
Technical Requirements
The applications can be altered to handle the encryption needs; however, the hardware
cant handle large key lengths.
The SQL Servers must run various jobs on demand. The IT staff isnt always available,
so a secure solution is desired that will allow the barn foreman to execute a few jobs on
the horse-care system server.
Some enhancements to the three systems are planned using the CLR integration.
Various assemblies will need to be installed on the servers in a secure manner.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions.
1. The new servers will be installed with Windows 2000 and SQL Server 2005. What type
of password requirements will be enforced?
a. Password expiration
b. Password policy (length, content)
c. Both of the above
d. None of the above
2. Which of the following algorithms would be best suited to provide encryption without
taxing the server hardware?
a. RSA 1024
b. AES_256
c. DES
d. Triple DES
3. To allow the barn foreman to run certain jobs on one SQL Server 2005 server, which
role should they be assigned?
a. sysadmin
b. SQLAgentOperatorRole
c. SQLAgentReaderRole
d. SQLAgentUserRole
4. One of the assemblies that will be used to enhance the horse-care system requires access
to read an RSS feed from an Internet Web site. What level of permissions should it be
installed with?
a. SAFE
b. UNSAFE
c. EXTERNAL_ACCESS
d. UNLIMITED
5. When the new servers are installed, database mirroring will not be enabled. Should the
database mirroring endpoint be created to prepare for the future activation?
a. Yes
b. No
6. What would be the preferred method of ensuring that new logins are sent to the barn
foreman?
a. Build an auditing routine into the application, and use it to add all logins.
b. Load the Windows security log into a table at the end of each day, and search for the
creation of a new login.
c. Use a paper form for new logins that requires the foremans signature before a login is
created.
d. Create a DDL trigger that responds to the server CREATE LOGIN event. Use it to
send e-mail to the foreman.
7. To allow the barn foreman to back up the horse-care database, what role should he be
assigned?
a. sysadmin
b. backupadmin
c. db_backupoperator
d. db_owner
8. Enhancements to the horse-care application will require tables in the financial database.
However, the users of the financial database should not access the horse-care tables
directly. What security measure should be used to easily assign permissions?
a. Server roles
b. Schema separation
c. Fixed database roles
d. Application roles
9. Currently, all users of the time-card application can access all tables and stored procedures in that database. However, future enhancements are planned to limit access to
stored procedures only. What role should be assigned to the users of this application?
a. db_owner
b. A user-defined role with specific permissions
c. db_datareader
d. db_datawriter
10. The president of the company is concerned about being able to connect to the servers at any time. Application security is handled in the applications, and the president is
assigned to the user-defined roles in SQL Server 2005 for access. She has no server roles
assigned. She would like to use the Dedicated Admin Connection to be sure she can
always connect. Can you grant rights to this endpoint to her login?
a. Yes, with GRANT CONNECT ON DAC To <login>.
b. Yes, by assigning the login to the sysadmin role.
c. No, there is no way to do this.
LESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
EXAM OBJECTIVE
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
assembly: A managed application
module that contains class
metadata and managed code
as an object in SQL Server. By
referencing an assembly, common
language runtime (CLR) functions,
CLR stored procedures, CLR
triggers, user-defined aggregates,
and user-defined types can be
created in SQL Server.
common language runtime
(CLR): A key component of
The purpose of SQL Server, or any relational database system, is to store data and make
it available for use by applications. All the security that is built into SQL Server is for the
purpose of protecting and ensuring only authorized access to your data. This Lesson looks
at the lowest level of securitythe objects. If you have to name it, its an object; if it has a
name, its an object.
Object is a general term for all the entities inside a database that store or interact with
your data. These include tables, views, stored procedures, functions, assemblies, and more.
The users who have access inside a database require permissions in order to use these
objects to read and write data.
150
Before you can assign permissions to the objects in your database(s), you must have some
type of strategy for securing the objects and the data they contain. This strategy should
define at a high level how youll handle the requirements for your applications.
The first recommendation that every SQL Server administrator should implement is to
adhere to the basic tenet of security and not assign any more access than necessary to perform
a job. This ensures that no one, whether accidentally or maliciously, accesses data or functions
they arent supposed to access. You control access with permissions.
The use of roles for assigning permissions is another part of a good permissions strategy.
Whether these are fixed roles or user-defined roles, managing permissions is greatly eased by
using roles for all permission assignments and not assigning any permissions to individual
users. Security is a hard process, and by making it easier to administer, its more likely that
your security decisions will be enforced and maintained.
REF
This use of roles includes administrative functions. SQL Server allows you to divide the
administrative tasks among a larger number of people without compromising the servers
overall security by granting everyone sysadmin permissions. Its recommended that if your
company uses multiple people to handle various tasks, you should ensure they arent granted
more permissions than necessary.
The next part of your strategy should address whether any permissions are assigned to the guest
user or the public account. Its highly recommended that you dont assign rights to either of
these objects and that you instead explicitly set up other roles to meet your needs. Because these
are shared objects among all users, its harder to remove permissions from them if necessary.
Some administrators have avoided using application roles because doing so requires that an
application be able to execute a stored procedure and switch permissions. However, this is a
great way to ensure that a specific application is used to access data. If you can control the
way the application executes stored procedures on login, this is a good choice. If not, then
you may want to design a policy that forbids the use of this type of role.
Last, you need to determine the degree to which youll allow the object-control permissions such as Alter, Create, and Drop for different objects or schemas. Most users dont need
these permissions, nor are they warranted, because most users wont change the structure of
database objects. However, you may have specific groups of developers or application administrators who need the ability to use these permissions. Your strategy should specify the cases
in which these permissions will be granted or which objects or schemas youll let specific users
change. However, as with individual object permissions, you should use roles to easily assign
permissions to and remove them from users by moving the users in and out of roles.
TAKE NOTE
In assigning data-access permissions and control permissions, you should use separate roles
for each.
Your policy should strike a balance between being as granular as necessary to meet the
business needs of your company and making the role assignment simple enough to ensure it
can be administered. The extreme level would create a role for each user, which would be an
unnecessarily complex administrative burden. Instead, you should assign a role to each major
job function and grant the appropriate permissions to the role. If there are exceptions for an
individual or a subset of the jobs members, create a role for the exceptions and then use a
DENY approach to remove the permissions they shouldnt be assigned. This way, a single role
retains the permissions to a large class of objects.
152 | Lesson 7
LAB EXERCISE
Understanding Permissions
A number of permissions can be assigned to different objects, each with different meanings that affect how your security plan applies to the database users. In this section,
youll briefly look at the various permissions and the objects to which they apply.
Before moving to permissions, you need a basic understanding of SQL Server terminology
related to security. The permissions assignment involves two entities. A principal is a user,
group, or process that requests some service. These are the individuals who receive permission
to perform some action or request a service. A securable is an object on which some
permission is granted. For example, in Exercise 7.1, the SalesManager group is a principal
that received the Select permission on the HumanResources.JobCandidate securable.
To apply a permission to an object, or to remove it, the administrator uses the Data Control
Language (DCL) commands. There are many DCL commands that are used to manage
access to SQL Server. The three DCL commands related to permissions are the following
commands:
CERTIFICATION READY?
You elect to apply the
REVOKE permissions
to all objects in your
database to user Nancy.
What are her effective
permissions for these
objects?
CERTIFICATION READY?
Know the difference
between GRANT,
REVOKE, and DENY.
GRANT. The GRANT command adds the permissions listed to the permission list
of the affected user or role. This command is used when you wish to let a principal
receive new permissions. In Exercise 7.1, you added the Select permission on the
HumanResources.JobCandidate table to the SalesManager role.
You can use the WITH GRANT option with this command. Doing so allows the
principal that receives the permission to in turn assign it to others.
REVOKE. REVOKE is the opposite of GRANT. It removes a permission on an object
from a principal. You use this command when a particular principal no longer needs the
specified permission on the securable. The lack of a permission leaves the object in an indeterminate state: access has been neither granted nor denied. The interaction of a user and a
role must resolve this ambiguity. If the ambiguity remains, Microsoft denies access.
There are two options with this command. The first parameter is GRANT OPTION,
which removes the specified principals ability to grant permissions. This doesnt affect
the permission set for the principal on the securable, but it prevents the principal from
assigning permissions to other principals.
The second parameter is CASCADE, which revokes the permission from the user as well
as any users to whom they have subsequently granted permissions.
DENY. The last permission command is DENY, which prevents the principal from
having the permission specified on the securable. Unlike REVOKE, this command doesnt
require permission on the object to have been previously granted. Instead, this command
prevents access whether the principal currently has the permission or is assigned it in the
future. The DENY permission overrides any other permission assignments.
This command is often used when overall permissions are granted to a role, but specific
securables contained in that role must not be accessed by a subset of the role members.
For example, suppose that all the sales managers should be allowed to SELECT from the
Production.ProductInventory table, but the junior managers (Bob and Steve) shouldnt
be allowed to UPDATE this table. Rather than creating a separate role for one group of
sales managers, you can use the DENY command to remove the ability to update data
from those two users only.
Using GRANT and DENY lets you easily implement the permission policy that fits your
business needs. As discussed earlier, using roles at the highest level ensures that your policy is
easy to administer. Using GRANT to assign permissions at this level and DENY to selectively
exclude individuals is the most efficient way to manage permissions. As your schema and
business needs change, you can use REVOKE to remove permissions that no longer apply.
You need to understand that the permission sets are hierarchical in nature. Permissions on a
container object, such as a database or schema, imply permissions on the objects contained
inside, such as the schemas inside the database or the objects inside a schema:
Alter. The Alter permission applied to individual objects includes all permissions except
the ability to change ownership. These permissions include the ability to create and drop
objects. If granted on a scope, such as schema, the principal can create or drop objects
within the scope.
Alter Any. This form of the Alter permission applies to either server-level or
database-level securables, such as logins or users, respectively. The principal receiving this
permission can create, alter, or drop any securable in the scope.
Backup. The Backup permission supersedes the Dump permission and allows the
principal to perform a backup on the database.
Control. The Control permission is equivalent to assigning ownership of the securables.
All available permissions are granted to the principal, and the principal in turn can grant
those permissions to others.
Create. The Create permission allows the principal to create new objects of the type
specified in the assigned scope, server, or database.
Delete. The Delete permission lets the principal user remove data from tables, views, or
synonyms.
Execute. The Execute permission allows the principal to invoke stored procedures,
functions, or synonyms.
Impersonate. The Impersonate permission can be granted at the login or user level and
allows the principal to change their security context to that of the assigned user or login.
Insert. The Insert permission applies to tables, views, and synonyms and allows the
addition of data to those objects.
Receive. The Receive permission allows (or denies) communication in the Service
Broker queue. Also: CLR Common Language Runtime; ACL Access Control List.
References. The References permission is required to access another object for the purpose of verifying a primary- or foreign-key relationship. This applies to scalar and aggregate functions, the Service Broker, tables, views, synonyms, and table-valued functions.
Restore. The Restore permission supersedes the Load permission and allows a backup to
be applied to a database in a restore operation.
Select. The Select permission lets a principal query a particular object and return the
data from a table, view, table-valued function, CLR function, or synonym.
Take Ownership. This permission is similar to the Windows ACL permission and allows
the principal to change ownership to themselves for the objects on which its granted.
Update. The Update permission confers the ability to change the individual values of
data in tables, views, and synonyms.
View Definition. This permission is new to SQL Server 2005 and provides more
granular control by allowing access to the metadata about a particular class of object.
Without this permission, the metadata definition of an object isnt available.
The granularity for most of these permissions is the individual object level with the exception
of the Select, Insert, Update, Delete, and References permissions. These permissions can be
assigned to individual columns if your business needs dictate this capability.
154 | Lesson 7
Before you implement the policy youve set up and make changes, you should examine
the existing structure of permissions to ensure that any changes you require wont result in
application issues. You also need to determine if there are conflicts with your policy and the
existing permissions and mitigate these issues.
If you arent setting up a new application or database, then you probably have existing
permissions in your database(s). You must examine two different types of object permissions:
the specific object-access permissions such as Select, Insert, Update, Delete, Execute, and
others that are used for accessing data; and the controlling permissions, such as Alter, Create,
Drop, and similar commands that convey control over an object.
The most common types of permissions are the data-access permissions granted on individual
objects. These permissions are shown in Table 7-1 along with the objects to which they can be
granted. The best practice is to assign these permissions to roles only, not to individual users.
Table 7-1
Object permissions
TAKE NOTE
P ERMISSION
OBJECTS
Select
Insert
Update
Delete
References
Execute
Receive
View Definition
TO
WHICH IT APPLIES
When youre assigning object permissions, include the security choices with the CREATE
or ALTER scripts used to develop the objects.
Unfortunately, SQL Server Management Studio doesnt include any easy tools to see all the
object permissions for a role. However, a great deal of information is available using functions
and views. You can determine the permissions for a role or a user by executing the fn_my_
permissions function under the context of the user or role. Changing the execution context of
the current user or login is discussed in the next section.
CERTIFICATION READY?
Know the different object
permissions and the
object types to which
they can apply. Can
Execute be applied to
a Service Broker query?
How about the View
permission?
The process of reconciling the existing permission set against the policy that has been determined is tedious. Its best tackled on a role-by-role basis, working from the new policy and
checking the permissions for the objects and securables against what is currently assigned. As
you identify missing permissions, you can use the GRANT command to add them to either
new or existing roles as specified in the policy.
If you encounter permissions that are currently granted on securables but shouldnt be in
the new security policy, you have a choice of how to proceed. If the permissions are at a
gross level, meaning an entire role currently has permissions it shouldnt, then you can use
REVOKE to remove these permissions. If this situation is at a lower level, such as a user or
users who should have permissions separate from the larger role, then you can create a role for
this subset that contains the DENY permission at the appropriate level.
Execution context specifies the way in which permissions are checked on statements and
objects.
By default, when a login connects to a SQL Server database, that login is used to determine
which permissions the user is assigned and which objects that user can access. However, SQL
Server includes the ability to change your context to that of another user, enabling you to
receive additionalor, potentially, reducedpermissions for the batches you execute.
Previous versions of SQL Server provided a limited ability to change your execution context
with the SETUSER command. This was a handy tool for system administrators, but it wasnt
useful for the average login because it was limited to sysadmin or db_owner roles. Because sometimes you need to escalate permissions for a single function, SQL Server has the EXECUTE AS
statement that allows for permission escalation by temporarily changing the user context.
TAKE NOTE
Microsoft has deprecated SETUSER, so your policy should recommend that it be replaced
in code wherever possible.
This command can be used in two cases, and you should address both with decisions
governing its use. In the first case, a particular function or stored procedure executes in a
specific logins context. The second case is for longer batches or sessions where a series of
commands are executed as another user. These two situations are discussed next.
156 | Lesson 7
CERTIFICATION READY?
Know the forms of the
EXECUTE AS command
and be prepared to
identify how the use of
this command would
alter the execution
context.
TAKE NOTE
Steve then grants Dean permission to execute this stored procedure. When Dean executes it, permissions are checked to be sure he can execute the module, but the permissions check on Steve.MyTable uses Steves permission set.
EXECUTE AS OWNER. This context uses the permission set of the module owner for
all objects referenced in the module. If the module doesnt have an owner, the owner of
the modules schema is used instead.
This is similar to EXECUTE AS SELF if the person creating the module is the same as
the owner at execution time. However, because object ownership can be changed, this
context allows the permission check to move to the new owner of the object.
In the three cases where execution context is set to a particular username, that user cant be
dropped until the execution context is changed.
USE MyDB
GO
EXECUTE AS USER = 'Kendall'
SELECT * FROM dbo.MyTable
. . . (more statements)
If Steve logged on to the SQL Server, the first statement sets the database context. The
next line changes the security context to that of Kendall. From that point forward, all the
statements that are executed have their permissions checked as if Kendall had logged on and
were executing them.
To use this statement, the calling login or user must have Impersonate permissions on the login
or user named in the command. This entails assigning that permission to those users or logins
that will need to change their context. As with other permissions, a database role is the best vehicle for assigning permissions for user-level context switches. For login-level changes, you must
use individual permissions, although you can use Windows groups if you have Windows logins.
All statements are executed with this new security context until one of the following events
occurs:
The session ends.
Another EXECUTE AS statement is run.
The REVERT command is issued.
The behavior of this command is similar to that of a trigger in that the calls to EXECUTE
AS nest themselves on a stack. The REVERT command returns you to the previous execution
context by default. Youll look at the REVERT command in more detail after examining the
options for EXECUTE AS.
When you change execution context with EXECUTE AS, a few options are available that can
give you more control over the security of your data:
Scope of the EXECUTE AS Statements. You can change context in one of two ways: at the
user level or at the login level. By choosing one of these, you define the scope of the impersonation that takes place. A login is a security object that exists at the server level, covering all
databases as fixed server roles. If you change your context to that of a login, then its as if you
logged on to the server as that user; the settings follow even if you change databases.
The syntax for this option is as follows:
EXECUTE AS LOGIN = <login name>
The user scope is only within the database in which its invoked and the user exists. This
prevents the inadvertent granting of permissions in other databases that the impersonated user
may have rights to access. This extends to USE <database> statements and linked server or
other distributed queries as well. Any of these cross-database statements will fail.
The syntax for this option is as follows:
EXECUTE AS USER = <user name>
NO REVERT. The NO REVERT option prevents the return of execution context to the
previous user or login. This is similar to an application role in that the session remains in the
context of the new user until the session is dropped. In essence, this command clears the stack
of execution contexts and prevents the return to any prior context.
If the REVERT command is run after this option has been specified, it has no effect. To
invoke this option, use the following syntax:
EXECUTE AS USER = <user name> WITH NO REVERT
158 | Lesson 7
NO REVERT COOKIE. As with many things in SQL Server, there is an exception to the
NO REVERT option. The execution context can be stored in a varbinary variable and used
to return to the previous execution context. This option allows the client to maintain the data
needed to restore the previous context.
The syntax to invoke this option is as follows:
DECLARE @cookie VARBINARY(100);
EXECUTE AS USER = <user name>
WITH NO REVERT
COOKIE = @cookie;
GO
To restore the context, you execute the following, assuming the @cookie variable contains the
correct cookie from the previous statement:
REVERT WITH COOKIE = @cookie
This type of statement ensures that the execution context can be reversed only by a client that
knows the correct cookie value. In connection-pooling statements, this can prevent another
client from changing its context without knowing this value.
Auditing
Its important to consider the auditing aspects of changing context. Once users change
their context, many of the functions associated with auditing return the name of the
new context, not the original login. The debate over which login or username should be
recorded may be philosophical, but the requirements of many enterprises dictate that the
auditing should be traceable back to an actual physical user, not an account.
Fortunately, there are a few ways in which you can access the underlying information about the
original authenticated user. The ORIGINAL_LOGIN() function returns the name of original
login (either Windows or SQL Server authenticated). This can be used in place of the USER_
NAME() or SUSER_SNAME() functions, which return the current context, not the original user.
If youre using Profiler to trace the execution of an application, Profiler includes a column
named SessionLoginName, which isnt visible or selected by default. This column contains
the value of the original login to the server; to see it, check the Show all columns check box
on the Events Selection tab, as shown in Figure 7-1.
Figure 7-1
Events Selection tab of the
Trace Properties dialog box
The default Profiler selections of NTLoginName and LoginName will change depending on
the context switch. This can lead to problems in providing a well-defined auditing trail.
LAB EXERCISE
In general, the use of EXECUTE AS for batch queries is best suited to testing and simulation
by administrators and developers. By changing context to that of a regular user, a developer
can easily and quickly determine whether the application will perform properly for a real
user. The permissions are checked, procedures executed, and data queries return just as if the
developer had logged on as that user.
Because the developer can quickly change back to their own context to make a change with
REVERT, this greatly speeds the development process without requiring tedious switching of
windows or applications, logging off and back on, or any of the previous techniques. Because
many companies use Windows Authentication, this also allows the developer to simulate
other logins on a single machine as different users.
TAKE NOTE
REF
The EXECUTE AS statement works only with logins. It doesnt work with groups, roles,
certificates, or any built-in accounts such as Local System, Local Service, or Network
Service.
Another way to use this feature in your security policy is to enable users to change context
with the database scope and create your own type of application role. By using the WITH
NO REVERT option, you can duplicate the functionality of the application role. You can
allow individual users to log on to SQL Server for auditing purposes; but by preventing them
from accessing any objects, you can force them to use the EXECUTE AS statement to obtain
permissions to query data.
Unlike with an application role, you can allow users to switch back to their original context.
This can be useful if you have more than one application and wish to let users switch between
them with different contexts without dropping their sessions.
The final place you should use the EXECUTE AS statement is in checking your permission
policy. A system administrator can use this command to impersonate any other users and
check which objects they can access and which they cant. This is the best way to ensure that
your permissions policy is correctly designed and implemented.
The use of encryption creates a large load on your database servers processor because complex
calculations are required to both encrypt and decrypt data. You have two ways to limit the
processing load on the server: Choose keys wisely, and limit the deployment of encryption.
160 | Lesson 7
REF
Choosing Keys
The key choice has two parts: the type of key and the use of the key.
As mentioned in Lesson 5, a variety of algorithms can be chosen for keys. These are divided
into two types, symmetric and asymmetric, as well as different lengths, commonly specified as
the number of bits in the key. Longer keys are more secure, but they require more processing
power. The general policy regarding key length is to choose the longest length you can, given
the processing capability your server can handle.
The algorithms have advantages and disadvantages that are beyond the scope of this text. If
you dont have a regulatory requirement for a particular algorithm, you should research them
to determine which is best suited for your application.
However, the use of each algorithm can greatly affect the performance of your server. The
recommendation is that you use an asymmetric key to secure the symmetric keys, which
in turn encrypt the data. This means a symmetric key is used to perform the encryption
and decryption of your data, because its faster with less of a load on the servers processor.
This key is in turn encrypted by an asymmetric key, which is more secure but requires
greater processing power to perform the encryption operations. The use of certificates
or server-created asymmetric keys is a decision you should make based on your existing
infrastructure. Certificates are more complex and require more administration because they
have expiration dates. Some applications, however, require certificates.
One other method of encryption is available, but the keys arent maintained by SQL Server.
If you use the ENCRYPTBYPASSPHRASE() function, then you supply a password that will
be used to encrypt or decrypt the data. In this case, the user or application must supply this
passphrase or password every time an encryption or decryption operation takes place. Because
the keys arent secured or recoverable, this method of encryption isnt recommended.
Deploying Encryption
The second aspect of encryption that you can control is the overall scale of how widely
it will be deployed in your database. The more columns you choose to encrypt, the more
processing power will be required both to store the data in a cipher format and to decrypt
the data each time that column is used in a query.
In addition to the processing requirements, encrypting data involves a few other performance
issues. Columns that are encrypted cant be efficiently indexed or searched using an index.
This means that primary keys, foreign keys, and columns that will be indexes for heavily used
queries shouldnt be encrypted. This requires careful consideration because many times the
column that you want to encrypt contains things like SSNs, credit card numbers, and so on
that you want to use as keys.
Both of these reasons should limit the amount of data you encrypt in your database. As you
seek to design an effective encryption scheme for your application, the meaning that can be
gleaned from unencrypted information should be carefully analyzed. Sometimes, encrypting
just a few sensitive columns can provide enough security without adversely affecting
performance.
For example, if you have a table of information that stores employees names, titles, and
annual salaries, it doesnt make sense to encrypt the entire table. If just the salary is encrypted,
then someone reading the table cant determine an individuals salary, and the table can still be
easily indexed and searched by name or title.
However, if you choose to encrypt the name, then assuming this isnt a key field, all the salary
values can be mapped to titles. This approach will disclose to anyone who can read the table a
CERTIFICATION READY?
Is a certificate an example
of an asymmetric key or a
symmetric key?
LAB EXERCISE
great deal of information about other employees based on their title. Similarly, if you encrypt
the titles, each persons name can be easily matched with a salary.
Determining which fields to encrypt is a difficult decision that each administrator must make
based on the actual tables and the data contained in each column. Only by analyzing your
situation will you be able to decide which fields need to be encrypted and balance that against
the performance penalties of using encryption.
In Exercise 7.3, youll encrypt a column of data two different ways.
One of the most interesting features for developers in SQL Server is the ability to code
modules in any .NET language and execute them in SQL Server. However, managing the
security of these objects is more important than ever, because the impact of these objects can
be seen in queries that may access millions of rows of data at a time.
LAB EXERCISE
By default, the ability to execute CLR objects in SQL Server is turned off. An administrator
must make a conscious decision to enable this functionality so that .NET assemblies
registered on the server can be executed.
Exercise 7.4 will walk you through enabling the CLR environment in SQL Server.
Creating Assemblies
Once CLR usage is enabled, then you can deploy or install .NET assemblies on the SQL
Server instance and create objects to use the methods inside these assemblies.
REF
These assemblies can be deployed automatically using Visual Studio .NET 2005/2008
or copied and manually added to SQL Server by an administrator. The ability to add an
assembly to SQL Server, however, requires the Create Assembly permission in either case.
This is similar to the ability to create a stored procedure or function. As previously noted,
only sysadmins can create assemblies with an UNSAFE permission set due to the lack of
restrictions on what code is called.
Integrating assemblies into SQL Server is slightly more complex than doing so with
procedures or functions because of the nature of a .NET assembly. Each assembly can call
other assemblies; as a result, SQL Server must also load those referenced assemblies. If they
dont exist, then SQL Server will load them as well.
If the assemblies already exist, then the same user or role must own the assembly, and the
referenced assembly must have been created in the same database. If not, then the creation of
the assembly will fail.
162 | Lesson 7
One other note about security when creating assemblies: Because theyre loaded from the file
system, the SQL Server must be able to access the files on the file system.
When this access occurs, it uses the permission set of the SQL Server service account unless
you use special programming techniques to enable impersonation of another account. These
advanced techniques require calls to the SqlContext.WindowsIdentity API. Consult the .NET
SDK for more information on this topic.
If you use impersonation, the calls must be out of process if they require data access. This
ensures the stability of the process and enables secure data access.
There are other restrictions on EXTERNAL_ACCESS. If an assembly attempts to access
external resources, and it was called by a SQL Server login, the access is blocked and an
exception is thrown. This also occurs if the caller isnt the original caller. If the caller is a
Windows login and the original caller of the module, then the security context of the SQL
Server service is used, as mentioned at the beginning of this section.
requires access to a system resource under a different ownership chain than the module,
unnecessary rights must be granted for this approach to work. Using module signing, you
can create a module that accesses the system resources under a login assigned to a certificate.
The certificate login will have the permissions to access the system resources. When users or
roles receive permission to execute the module, they will receive the permissions to access the
system resources only as long as the module is being invoked. Once it completes, they will no
longer be able to access the system resources.
As such, its important that you develop a strong policy to guide how CLR objects are
integrated into your SQL Server environment to guarantee a secure system. Your policy
should consist of three parts to ensure that you maintain control over the assemblies you
integrate into your database environment. (This assumes youll allow the CLR to be enabled
on your server. If not, then that is the policy you should set.)
The first part of your policy uses GRANT, REVOKE, and DENY permissions you apply
to the assemblies to allow objects to be created using them. Because this policy affects the
functions and modules when theyre executed, be sure you limit the rights to execute these
functions to those who need to do so. If one group uses a CLR module to load data from a
web service, dont grant rights to execute the module to all your users. Create a role, and limit
the execution rights to that group.
The second part of your policy deals with the assemblys permission set. You should assign
the minimum set of permissions necessary when the module is created. Unless an assembly
truly needs to access resources outside the server, it should have the SAFE permission set
applied. Stringent requirements should be met before you create UNSAFE-level assemblies.
Your policy for developing these types of assemblies should have guidelines for what types
of functions will be granted permissions other than the SAFE level; that level should be the
default for all assemblies unless the need for the other levels is proven.
For those modules that access outside resources, youll want to make sure they will work
correctly in a multirow result set. For modules that are designed to work on a single row or a
few fields of data, you may wish to set a policy to prevent their use in queries or updates that
will affect large sets of data.
In addition to setting the permission-set level, you should also be sure youre aware of the
interactions between assemblies. Utility assemblies contain code required by other assemblies,
but these need to be owned by the same user or schema and in the same database for the
assemblies to reference each other. If they arent, the code must be restructured to exist inside
a single assembly. The policy you develop should specify these restrictions to ensure the
resulting application functions as expected when deployed.
In setting this policy, you should also limit who has the right to add assemblies. Ideally, only
administrators should be allowed to create assemblies; if you assign rights to other users, be
sure that its a limited group and that each assembly added is carefully documented as to its
purpose and use (especially if it doesnt use the SAFE permission level).
The last part of your policy that you need to design is the code policy for the assembly.
Although its likely that code standards for .NET development exist in most environments,
these assemblies will be called from within SQL Server and potentially called many times for
164 | Lesson 7
a single query. The assembly must be built to handle the stresses of executing inside the server
environment and should be coded to ensure that it doesnt affect the stability of SQL Server.
Your environment may specify requirements for performance or load to ensure an assembly
doesnt slow the server or adversely affect performance. Because these assemblies will act on
large sets of data that will be used for updates, reports, and business decisions, the modules
need to be thoroughly examined for accuracy in addition to performance.
For assemblies that access resources outside SQL Server, make sure the work being performed
can complete in a timely manner and not affect the performance of other queries or cause
instability with the SQL Server instance. This is especially important if any modules work
directly with memory or the servers configuration.
S K I L L S U M M A RY
The security in your database is the final level of protection for your data. After logging in,
mapping to a user, and receiving the security tokens for any role memberships, the Select,
Insert, Update, Delete, Execute, and other T-SQL permissions applied to objects must be set to
meet your business requirements, but in as limited a way as possible.
Developing a strong policy is important for maintaining the security of your data, but it must
be applied to be effective. Your policy should be analyzed against the existing permissions and
any deficiencies brought into compliance. A limited number of exceptions may be required
because of preexisting applications or requirements, but they should be kept to a minimum.
SQL Server provides the ability of users to impersonate others and execute commands in a
security context other than their own. A secure SQL Server instance ensures that this is
controlled and limited to those cases where its truly needed. The impersonation capabilities
also can affect auditing systems and capabilities, so these functions should be examined to
guarantee that they still perform the functions that are required.
Encryption is a wonderful way to secure your data, but it brings with it a number of performance trade-offs. A good policy will find a way to balance the secure control of your data
with the need to meet performance goals.
The CLR integration into SQL Server is an incredible capability that provides almost unlimited
ways to manipulate and analyze your data. However, it can drastically reduce the security
of your instance if controls arent developed around the assemblies you allow on your
server. This is especially true of any CLR access outside of the SQL Server instance. A strong
policy should be developed early on to eliminate the introduction of new points of attack or
instability on the database server.
For the certification examination:
Understand how to design a permissions strategy. You should know the different parts of
the permissions strategy and how to structure your policy in order to meet your security
needs.
Know the permission-assignment commands. Be sure that you understand the meanings
and use of GRANT, REVOKE, and DENY.
Understand how to analyze existing permissions. You should be able to analyze existing
permissions and reconcile these against your security permission policy.
Understand execution context. Be sure that you understand how to determine and change
your execution context and the implications of doing so.
Know the implications of using the CLR. The CLR environment changes the capabilities of
SQL Server. You should understand the potential impact of these capabilities.
Knowledge Assessment
Case Study
Jacks Steamed Shrimp
Jacks Steamed Shrimp is a small food chain that specializes in steamed seafood and has
a number of locations in seaside resort towns. Each location has outside tables for diners
to enjoy and a thriving delivery business to the surrounding areas. The company has
grown to more than 20 locations and 250 employees.
Jacks has developed two applications internally that are used to run the day-to-day
operations of the business. One is designed to handle the point of sale (POS) for the
food sales, both in-store and telephone orders for delivery. The other maintains the
inventory and food orders required to ensure that none of the locations run out of
supplies.
Planned Changes
New applications are being rolled out to replace existing applications that currently run
on the same database. Some schema changes will be included to extend functionality,
but a number of the old objects in both the Inventory and Sales databases will be
maintained.
Some new users and roles will be required, but the existing users will be reassigned new
permissions based on a policy developed for the new applications. Each database will
have two new roles: AppUsers and AppAdmins, with permissions assigned based on the
capabilities of the users.
Existing Infrastructure
The SQL Server 2005 server runs on a Windows 2003 server. All employees have a
domain account for logging in to the applications and various terminals.
The SQL Server 2005 instance was installed with the default options.
Each clerk carries a keycard on which a digital certificate is stored; this certificate
uniquely identifies that employee.
Business Requirements
A number of enhancements have been written in CLR language to handle a few
complex business requirements.
166 | Lesson 7
A number of regular customers keep their credit card numbers on file, and these
must be encrypted.
The developers need to have rights to the tables used for data lookups on the
Inventory system. However, the junior developers shouldnt have rights to the
detailed inventory tables.
Technical Requirements
The inventory application uses a web service to gather data from business partners
and must access an Internet web server for this data.
Individual clerks need to be able to input the credit card numbers for clients, but
they shouldnt have access to the tables where this information is stored. Its decided
that the execution context for the stored procedures that insert the data should be
changed to sales manager.
A development user-defined role is set up in each database. This role is a member of
the db_datareader role.
The POS schema contains two CLR modules: GetSpecials, which builds customized
coupons for returning clients; and CalcRoute, which determines the driving
directions for deliveries.
The Inventory database contains a CLR module called OrderPredictor that
determines whether a product needs to be reordered when its called.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions:
1. You create an assembly on the server for one of the new .NET modules given to you by
a developer. You create a function for this assembly and assign security rights, but it does
not seem to work. What is wrong?
a. .NET assemblies should be called directly, not through a function.
b. A stored procedure is used to access .NET assemblies.
c. The CLR subsystem is not enabled.
d. The module is not trusted.
2. Which level of permissions should be assigned when creating the assemblies that call the
web service?
a. SAFE
b. UNSAFE
c. EXTERNAL_ACCESS
d. REMOTE
3. You do not want to change the overall rights for the developers role because the senior
developers should be allowed to access the Inventory table. What rights should you
assign to the junior developers?
a. REVOKE SELECT ON INVENTORY
b. DENY SELECT ON INVENTORY
c. REMOVE SELECT ON INVENTORY
d. EXCEPTION SELECT ON INVENTORY
4. If developers build a module that will handle the proper casing of customer names
when they are queried for printing on the delivery labels, what permission set should be
assigned this module?
a. UNSAFE
b. EXTERNAL_ACCESS
c. SAFE
d. LOW
5. One of the developers wants to use the CalcRoute module in the POS database from the
OrderPredictor module in the Inventory database to help give suppliers directions to the
locations. Can these two modules call each other?
a. Yes
b. No
6. There is a customer defaults table that contains three fields: the customer code, the
last order, and a credit card for automatic ordering. Which of these columns should be
encrypted for security?
a. All three
b. The last order and credit card number
c. The customer code and credit card number
d. The credit card number
7. One of your developers is building stored procedures on their test system that will
require elevated privileges for its execution. It is decided to elevate privileges for the
module to that of the owner of the procedure at execution time. What clause should
the developer use when creating the module on his test system to ensure it is deployed
correctly on the production system?
a. EXECUTE AS SELF
b. EXECUTE AS <developer user name>
c. EXECUTE AS OWNER
d. EXECUTE AS CALLER
8. The auditing company was granted temporary access to the POS.CustomerDefaults
table during tax season by issuing GRANT SELECT ON POS.CustomerDefaults TO
Auditors. To remove these permissions, what should you execute for the Auditors role?
a. REVOKE SELECT ON POS.CustomerDefaults
b. DENY SELECT ON POS.CustomerDefaults
c. REMOVE SELECT ON POS.CustomerDefaults
d. GRANT NONE ON POS.CustomerDefaults
9. You wish to allow the senior developer access to the POS.Products table and want to let
him give this permission to other developers without granting him any fixed database
roles. What clause should you use with the GRANT command to achieve this?
a. WITH CASCADE
b. WITH GRANT
c. WITH ALLOW
d. WITH OWNERSHIP
10. After a trial period, you realize that the developers should not have permissions on the
production POS database. So, you want to revoke permissions from the senior developer
along with any permissions he has granted to others. What clause should you use with
the REVOKE clause?
a. WITH REMOVE
b. WITH REVOKE
c. CASCADE
d. FROM ALL
LESSON
Designing a
Physical Database
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
EXAM OBJECTIVE
Foundational
Foundational
Foundational
Foundational
Design tables.
Decide if partitioning is appropriate.
Foundational
Foundational
Foundational
Foundational
Foundational
Design filegroups.
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Design views.
168
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
constraint: A property assigned
to a table column that prevents
certain types of invalid data
values from being placed in the
column. For example, a UNIQUE or
PRIMARY KEY constraint prevents
you from inserting a value that is
a duplicate of an existing value,
a CHECK constraint prevents you
from inserting a value that does
not match a specified condition,
and NOT NULL prevents you from
leaving the column empty (NULL)
and requires the insertion of
some value.
database: A collection of
information, tables, and other
objects organized and presented
to serve a specific purpose,
Think about your house for a moment, then your office, classroom, gym locker, car, and
any other place you habitually haunt. These locations are full of objects you ownsuch
as clothes, food, DVDs, your copy of this textbook, tools, and so on. Most of your stuff
is probably at your home, but unless youre severely messy, its unlikely that you randomly
toss your stuff into your house and lose hope you can find it again later.
What you do is try to store your various objects in containers (such as cabinets, dressers, or
bookshelves). More than likely, you also keep similar objects together; for example, your dress
shirts are hung next to one another in the closet, your Star Trek videos are all neatly lined up
on a shelf in some sort of order, and so on.
Why do you organize your objects? Because if you didnt, you couldnt find them later, and
if you couldnt find them, you couldnt use them. If you cant use them, whats the point of
having them? If you dont know where an object is when you want it, youll spend a great deal
of unproductive time trying to find it. These principles also hold true with SQL Server.
SQL Server is full of tables, views, stored procedures, and other objects. When it comes to
your clothes, food, tools, and so on, you need containers to store themwith SQL Server,
those containers are databases.
It makes sense that before you begin creating objects, such as tables and views, you must
create the database that will contain those objects. In this Lesson, youll learn what you need
to do while creating, configuring, and administering databases in order to maximize their
performance. As with most tasks in the book, planning is the hard partbut the rewards of a
well-constructed database plan are well worth it.
Databases consist of up to three types of files: primary data files, secondary data files, and
transaction log files. The primary data files store user data and system objects that SQL Server
needs to access your database. The secondary data files store only user information and are
used to expand your database across multiple physical hard disks. The transaction log files
allow up-to-the-minute recoverability by keeping track of all data modifications made on the
system before theyre written to the data files.
170 | Lesson 8
You dont make decisions on how the database should be designed in a vacuum or based on
personal whimsy. Because youre in the process of building a database infrastructure, you
need to consider some critical issues: performance, and the users or organizations business
requirements.
A SQL Server database consists of a collection of tables that stores a specific set of structured
data. A table contains a collection of rows, also referred to as records, and columns, also
referred to as attributes. Each column in the table is designed to store a certain type of information; for example, dates, names, dollar amounts, and numbers.
Tables have several types of controls, such as constraints, triggers, defaults, and customized
user-data types, which are used to protect and guarantee the validity of the data. As youll
see later, tables can have indexes similar to those in books that help you find rows quickly. A
database can also contain procedures that use Transact-SQL or .NET Framework programming code to perform operations with the data. These operations include creating views that
provide customized access to table data or running user-defined functions that perform complex calculations on a subset of rows.
Planning a Database
The first step in designing and creating a database is to develop a plan. A plan serves two
purposes: It provides a guide to follow when implementing the database, and it serves as
a functional specification for the database after it has been implemented.
The nature and complexity of a database, and the process of planning it, can vary significantly. A database can be relatively simple and designed for use by a single person, or it can
be large and complex and designed, for example, to handle all the banking transactions for
thousands of clients. In the first case, the database design may be little more than a few notes
on some scratch paper. In the latter case, the design may be a formal document hundreds of
pages long that contains every possible detail about the database.
Regardless of the databases size and complexity, there some basic principles you should always
follow:
Gather information. Before creating a database, you need a good understanding of what
the database is for and what its expected to do. Is it a new database? Is it a modification of
an existing electronic one? Or is it intended to replace a paper-based or manually performed
information system?
By reviewing the background and any existing systems, paper or electronic, youll get most
of the information you need. Collect copies of customer statements, inventory lists, management reports, and any other documents that are part of the existing system, because these will
be useful to you in designing the database and the interfaces.
You should also review the business requirements of the database and organization and
make sure they coincide. Another key task is to interview the stakeholders and everyone else
involved in the system to determine what they do and what they need from the database.
Its also important to identify what they want the new system to do, and also to identify the
problems, limitations, and bottlenecks of any existing system. Your design should take advantage of every optimal opportunity and, at the same time, minimize the physical shortcomings
and bottlenecks that may exist in the system, at least until you can correct them.
Inventory the objects. As part of your plan, you need to review the planned objects (and inventory those that exist, if youre modifying an existing database). You should do the following:
Efficient in this case doesnt mean minimum size. Efficiency refers to structuring the database
so that data stays organized and changes are easy to make without side effects. Minimizing
storage size is sometimes a product of normalization, but its not the main goal.
Normalization primarily acts to preserve the integrity of your data. No matter what operations are performed in your database, it should be as difficult as possible to insert meaningless
data. Normalization recognizes four types of integrity:
Entity integrity. Maintaining data consistency for each row (or instance) in the table.
This is often enforced with a unique identifier which can, but need not, be a primary key.
Domain integrity. Maintaining data consistency with a column (or attribute) in a table.
This is often enforced with validity checking (null or not null, range or value).
Referential integrity. Maintaining data consistency between columns in a table or
between tables in the database. This is often enforced with a foreign key.
User-defined integrity. Maintaining data consistency by defining specific rules that
do not fall into one of the other integrity categories. This is often enforced with stored
procedures and triggers.
Normalizing a logical database design involves using formal methods to separate the data into
multiple related tables. Several narrow tables with fewer columns are characteristic of a normalized
database. A few wide tables with more columns are characteristic of a non-normalized database.
Some of the benefits of normalization include the following:
172 | Lesson 8
malization can ruin the integrity of your data and lead to slower performanceif you
denormalize too far, you end up including many extra fields in each table, and it takes
time to move that extra data from one place in your application to another.
The principal goal of normalization is to remove redundancy from the data. By contrast,
denormalization deliberately introduces redundancy into your data. Theoretically, you should
never denormalize data. However, in the real world, things arent always that simple, and you
may need to denormalize data to improve performance. For example, if you have an overnormalized database, it can slow down the database server because of the number of joins that
must be performed to retrieve data from multiple tables.
TAKE NOTE
When youre forced to denormalize data for performance, make sure you document your
decision so that another developer doesnt think you made a mistake.
No hard and fast rules tell you exactly how (or whether) to denormalize tables in all circumstances, but you can follow these basic guidelines:
If your normalized data model produces tables with multipart primary keys, particularly
if those keys include four or more columns and are used in joins with other tables, you
should consider denormalizing the data.
If producing calculated values such as maximum historic prices involves complex queries with many joins, you should consider denormalizing the data by adding calculated
columns to your tables to hold these values. SQL Server supports defining calculated
columns as part of a table, as youll see shortly.
If your database contains extremely large tables, you should consider denormalizing the
data by creating multiple redundant tables instead. You may do this either by column
or by row. For example, if the Medications table contains many columns, and some of
these (such as patent date) are infrequently used, it will help performance to move the
less frequently used columns to a separate table. With the volume of the main table
reduced, access to this data will be faster. If the Medication table is worldwide, but most
queries require information about medications from only one region, you can speed up
the queries by creating separate tables for each region.
If data is no longer live and is being used for archiving, or is otherwise read-only, denormalizing by storing calculated values in columns can make certain queries run faster.
If queries on a single table frequently use only one column from a second table, consider
including a copy of that single column in the first table.
As youll see, Microsoft has made the documentation and diagramming processes less painful
and designed them so that you can use some of the processes to modify your database.
LAB EXERCISE
TAKE NOTE
Maintaining a backup script that lets the user re-create all users, groups, logins, and
permissions
Creating or updating database development code
Creating a test or development environment from an existing schema
Training newly hired employees
Diagramming a Database Structure
Back when electronic databases were young, the only way you could diagram your database
was by sketching it on a piece of paper or drawing it on a blackboard. Thankfully, those days
are gone. SQL Server ships with a tool called Database Diagram Designer that allows you to
design and visualize a database to which youre connected. To help you visualize a database,
it can create one or more diagrams illustrating some or all of the databases tables, columns,
keys, and relationships.
Youll use database diagrams in Exercise 8.2.
Designing Tables
Tables are database objects that contain all the data in a database. Each database has at least
one table, and frequently more. Data in tables is organized in a row-and-column format from
which is derived the relational part of your relational database management system. Each
row represents a unique record, and each column represents an attribute within the record.
Figure 8-1 shows the Person.Contact table from the AdventureWorks database. It contains a
row for each contact and columns representing contact information such as IDs, titles, names,
and e-mail addresses, among others.
Figure 8-1
Tables consist of columns and
rows, also called attributes
and records.
174 | Lesson 8
When you design a database, you should first determine what tables it needs, the type of data
that goes in each table, and, as you saw earlier in the book, which users can access each table.
The recommended way to create a table is to first define everything you need in the table,
including data restrictions and other components. Key decisions you need to make about the
table include the following:
The types of data the table will contain
The number of columns in the table and, for each column, the datatype and length, if
its required
Which columns will accept null values
Whether and where to use constraints or defaults and rules
The types of indexes that will be needed, where required, and which columns are
primary keys and which are foreign keys
Another good method for designing a table, especially in a complex or critical environment,
is to create a basic table, add some data to it, and then experiment with it for a while. This
method is useful because it gives you an opportunity to get an idea of what transactions are
common and what types of data are entered most frequently before you commit to a firm
design by adding constraints, indexes, defaults, rules, and other objects.
TAKE NOTE
To see what a partitioned table looks like, examine the AdventureWorks database:
The TransactionHistory and TransactionHistoryArchive tables are partitioned on the
ModifiedDate field.
Partitioning a table improves performance and simplifies maintenance. When you split a large
table into smaller, individual tables, queries that access only a fraction of the data can run
faster because there is less data to scan. Maintenance tasks, such as rebuilding indexes or backing up a table, can also run more quickly.
You can partition a database without splitting tables by physically putting tables on individual
disk drives. Putting a table on one drive and related tables on another drive can improve
query performance because when queries that involve joins between the tables are run, multiple
disk heads read data at the same time. SQL Server filegroups can be used to specify the disks
on which to put the tables.
There are three types of partitioning:
Hardware partitioning. Hardware partitioning designs the database to take advantage of
the available hardware architecture, including multiprocessors and Redundant Array of
Inexpensive Disks (RAID) configurations.
Horizontal partitioning. Horizontal partitioning divides a table into multiple tables with the
same number of columns but fewer rows. For example, suppose a hospital has a table with a
billion rows of patient billing data. The table could be partitioned horizontally into 12 tables,
with each smaller table containing a months worth of data. If a user issues a query requiring
data for a specific month, it references only the appropriate table.
If you opt to partition tables horizontally, you should partition the tables so that queries reference as few tables as possible. Otherwise, excessive UNION queries, used to merge the tables
logically at query time, can affect performance.
Horizontal partitioning is typically used when data can be divided based on age or use. For
example, a table may contain data for the last five years, but only data from the current year
is regularly accessed. In this case, it makes performance sense to partition the data into five
tables, with each table containing data from only one year.
Vertical partitioning. Whereas horizontal partitioning divides tables based on rows, vertical
partitioning divides a table into multiple tables containing fewer columns. There are two
types of vertical partitioning:
Normalization: the process of removing redundant columns from a table and putting them
in secondary tables that are linked to the primary table by primary key and foreign key relationships.
Row splitting: divides the original table vertically into tables with fewer columns. Each
logical row in a split table matches the same logical row in the others. For example, joining
the tenth row from each of the split tables re-creates the original row.
Like horizontal partitioning, vertical partitioning lets queries scan less data, thus improving
query performance.
Vertical partitioning can also have an adverse impact on performance because analyzing data
from multiple partitions requires queries that join the tables, slowing the process. Vertical
partitioning can also negatively affect performance if partitions are very large.
Take another look at Figure 8-1. In this case, assume the ContactID field is defined as a primary key. As you can see, you already have a contact with a ContactID of 1 in the table. If
one of your users tries to create another contact with a ContactID of 1, they will receive an
error and the update will be rejected, because ContactID 1 is already listed in the primary
keys unique index. (This is just an examplethe ContactID field has the identity property
set, which automatically assigns a number with each new record inserted and wont allow you
to enter a number of your own design.)
176 | Lesson 8
Stability. If the value in the column is likely to change, it wont make a good primary key.
When you relate tables together, youre making the assumption that you can always track the
relation later by looking at the primary key values.
Minimality. The fewer columns in the primary key, the better. A primary key of customer_id
and order_id is superior to one of customer_id, order_id, and order_date. Adding the extra
column doesnt make the key more unique; it merely makes operations involving the primary
key slower.
Familiarity. If the users of your database are accustomed to a particular identifier for a type
of entity, it makes a good primary key. For example, you might use a part number to identify
rows in a table of parts.
TAKE NOTE
When a column has mostly unique values, its said to have high selectivity. When a
column has several duplicate values, its said to have low selectivity. The primary key field
must have high selectivity (entirely unique values).
LAB EXERCISE
In Exercise 8.3, youll examine the Person.Contact table and modify a primary key.
M EDICATIONS
PHYSICIANS
MedicationID (PK)
PhysicianID (PK)
PhysicianID (FK)
LastName
Class
FirstName
Number
Specialty
Frequency
DateofHire
You can relate the two tables on the PhysicianID column that they have in common. If you
use the PhysicianID field in the Physicians table as the primary key (which you already have),
you can use the PhysicianID field in the Medications table as the foreign key that relates the
two tables. You wont be able to add a record to the Medications table if there is no matching
record in the Physicians table. Not only thatyou cant delete a record in the Medications
table if there are matching records in the Physicians table.
With a foreign key in place, you can protect records not only in one table but in associated
related tables from improper updates. Users cant add a record to a foreign-key table without
a corresponding record in the primary-key table, and primary-key records cant be deleted if
they have matching foreign-key records.
The relationship between a primary key and a foreign key can take one of several forms. It
can be one-to-many. It can be one-to-one, where precisely one row in each table matches
one row in the other. Or it can be many-to-many, where multiple matches are possible
(imagine a table of physicians and a table of patients, each of whom might see many
physicians).
TAKE NOTE
178 | Lesson 8
Binary. This datatype includes fixed-length, binary data with a maximum length of 8,000 bytes.
Its interpreted as a string of bits (for example, 11011001011) and is useful for storing anything
that looks better in binary or hexadecimal shorthand, such as a security identifier.
Bit. This datatype can contain only a 1 or a 0 as a value (or null, which is no value).
Char. This datatype includes fixed-length, non-Unicode character data with a maximum
length of 8000 characters. Its useful for character data that will always be the same length,
such as a State field, which will contain only two characters in every record. This uses the same
amount of space on disk no matter how many characters are stored in the field. For example,
char(8) always uses 8 bytes of space, even if only four characters are stored in the field.
Datetime. This datatype includes date and time data from January 1, 1753, to December
31, 9999, with time values rounded to increments of .000, .003, or .007 seconds. This takes
8 bytes of space on the hard disk and should be used when you need to track very specific
dates and times.
Decimal. This datatype includes fixed-precision and scale-numeric data from 1038 + 1
through 1038 1 (for comparison, this is a 1 with 38 zeros following it). It uses two
parameters: precision and scale. Precision is the total count of digits that can be stored in the
field, and scale is the number of digits that can be stored to the right of the decimal point. If
you have a precision of 5 and a scale of 2, your field has the format 111.22. This type should
be used when youre storing partial numbers (numbers with a decimal point).
Float. This datatype includes floating-precision number data from 1.79E + 308 through
1.79E + 308. Some numbers dont end after the decimal pointpi is a fine example. For such
numbers, you must approximate the end, which is what float does. For example, if you set a
datatype of float(2), pi will be stored as 3.14, with only two numbers after the decimal point.
Identity. This isnt a datatype, but a property, typically used in conjunction with the int
datatype. Its used to increment the value of the column each time a new record is inserted.
Int. This datatype can contain integer (or whole number) data from 231 (2,147,483,648)
through 231 1 (2,147,483,647). It takes 4 bytes of hard-disk space to store and is useful for
storing large numbers that youll use in mathematical functions.
Money. This datatype includes monetary data values from 263 (922,337,203,685,477.5808)
through 263 1 (922,337,203,685,477.5807), with accuracy to a ten-thousandth of a monetary unit. It takes 8 bytes of hard-disk space to store and is useful for storing sums of money
larger than 214,748.3647.
Nchar. This datatype includes fixed-length, Unicode data with a maximum length of 4,000
characters. Like all Unicode datatypes, its useful for storing small amounts of text that will be
read by clients who use different languages.
Numeric. This is a synonym for decimal.
Nvarchar: This datatype includes variable-length, Unicode data with a maximum length of
4,000 characters. Its the same as nchar, except that nvarchar uses less disk space when there
are fewer characters.
Nvarchar(max). This datatype is just like nvarchar; but when the (max) size is specified, the
datatype holds 231 1 (2,147,483,647) bytes of data.
Real. This datatype includes floating-precision number data from 3.40E + 38 through
3.40E + 38. This is a quick way of saying float(24)its a floating type with 24 numbers
represented after the decimal point.
Smalldatetime. This datatype includes date and time data from January 1, 1900, through
June 6, 2079, with an accuracy of 1 minute. It takes only 4 bytes of disk space and should be
used for less specific dates and times than youd store in datetime datatype.
Smallint. This datatype includes integer data from 215 (32,768) through 215 1 (32,767).
It takes 2 bytes of hard-disk space to store and is useful for slightly smaller numbers than you
would store in an int type field, because smallint takes less space than int.
Smallmoney. This datatype includes monetary data values from 214,748.3648 through
214,748.3647, with accuracy to a ten-thousandth of a monetary unit. It takes 4 bytes of space
and is useful for storing smaller sums of money than would be stored in a money type field.
Sql_variant. This isnt a datatype either; it lets you store values of different datatypes.
The only values it cant store are varchar(max), nvarchar(max), text, image, sql_variant,
varbinary(max), xml, ntext, timestamp, or user-defined datatypes.
Timestamp. This datatype is used to stamp a record with an incrementing counter when
the record is inserted and every time its updated thereafter. Its useful for tracking changes to
your data.
Tinyint. This datatype includes integer data from 0 through 255. It takes 1 byte of space on
the disk and is limited in usefulness because it stores values only up to 255. Tinyint may be
useful for something like a product-type code when you have fewer than 255 product codes.
Uniqueidentifier. The NEWID() function is used to create globally unique identifiers that
look like the following example: 6F9619FF-8B86-D011-B42D-00C04FC964FF. These
unique numbers can be stored in the uniqueidentifier type field; theyre useful for creating
tracking numbers or serial numbers that have no possible way of being duplicated.
Varbinary. This datatype includes variable-length, binary data with a maximum length of
8,000 bytes. Its just like binary, except that varbinary uses less hard-disk space when fewer
bits are stored in the field.
Varbinary(max). This datatype has the same attributes as the varbinary datatype; but when
the (max) size is declared, the datatype can hold 231 1 (2,147,483,647) bytes of data. This is
very useful for storing binary objects like JPEG image files or Word documents.
Varchar. This datatype includes variable-length, non-Unicode data with a maximum of 8,000
characters. Its useful when the data wont always be the same length, such as in a first-name
field where each name has a different number of characters. This uses less disk space when
there are fewer characters in the field. For example, if you have a field of varchar(20), but
youre storing a name with only 10 characters, the field will take up only 10 bytes of space,
not 20. The field will accept a maximum of 20 characters.
Varchar(max). This is just like the varchar datatype; but you specify a size of (max). The
datatype can hold 231 1 (2,147,483,647) bytes of data.
Xml. This datatype is used to store entire XML documents or fragments (a document that is
missing the top-level element).
TAKE NOTE
The text, ntext, and image datatypes have been deprecated as of the 2005 version of SQL
Server. You should replace them with varchar(max), nvarchar(max), and varbinary(max)
when you design tables and replace them in existing tables.
180 | Lesson 8
SQL Server 2008 introduces eight new datatypes. Four new date and time related datatypes
provide a greater degree of control and precision of chronological data. Two new spatial
datatypes provide specific methods of storing positional data. The other two new datatypes
provide abilities to better handle large data objects and hierarchically structured data. The
following is a list of the new SQL Server 2008 datatypes, their uses, and limitations:
Date: This datatype uses the format of YYYY-MM-DD and is compliant with ANSI standards.
It uses 3 bytes of storage and can contain values from 0001-01-01 through 9999-12-31.
Datetime2: This datatype provides for a higher degree of time precision. This datatype can
store values from 0001-01-01 00:00:00.0000000 through 9999-12-31 23:59:59.9999999 and
uses from 6 to 8 bytes of storage depending upon the time precision.
Datetimeoffset: This datatype is different from the other date and time datatypes in that it contains a timezone offset value. The format and range is the same as the new Datetime2 datatype
except that an offset in hours and minutes follows the time value. This offset value can be either
positive or negative. Storage space ranges from 8 to 10 bytes depending upon the time precision.
TAKE NOTE
Using Constraints
CERTIFICATION READY?
Rules (constraint objects
defined once and used
on multiple objects)
have been available
in previous editions of
SQL Server and remain
available in both SQL
Server 2005 and SQL
Server 2008. Know
when to use them if
only to eliminate a
possible answer on your
certification test.
As youve seen from the beginning of this Lesson, tables are wide open to just about any
kind of data when theyre first created. The only starting restriction is that users cant violate the datatype of a field; other than that, the tables are fairly insecure from whatever
your users want to put in them.
So far youve seen that getting control of the table isnt difficult, but it does require work.
Youve learned how to use primary and foreign keys to control what happens to data and limit
what can be entered and what cant.
Now, delve into the issue of how to restrict what data your users can enter in a field and how
to maintain data integrity. You can enforce three types of integrity:
Entity integrity. Entity integrity is the process of making sure each record in the table is unique
in some way. Primary keys are the main way of accomplishing this; they can be used with foreign
keys in enforcing referential integrity. Unique constraints are used when the table includes a field
that isnt part of the primary key but that needs to be protected against duplicate values.
Referential integrity. Referential integrity is the process of protecting related data that is stored
in separate tables. A foreign key is related to a primary key. The data in the primary key table
cant be deleted if there are matching records in the foreign-key table, and records cant be
entered in the foreign-key table if there is no corresponding record in the primary-key table. The
only way around this behavior is to enable cascading referential integrity, which lets you delete or
change records in the primary-key table and have those changes cascade to the foreign-key table.
Domain integrity. Domain integrity is the process of restricting what data your users can enter
in a field. Check constraints and rules can be used to validate the data the users try to enter
against a list of acceptable data, and defaults can be used to enter data for the user as defaults.
182 | Lesson 8
TAKE NOTE
A unique constraint
can be referenced by a
foreign-key constraint.
You should use a unique constraint when you need to ensure that no duplicate values can
be added to a field that isnt part of your primary key. A good example of a field that might
require a unique constraint is a Social Security Number field, because all the values contained
therein need to be unique; yet there would most likely be a separate employee ID field that
would be used as the primary key.
Normally, computed columns are treated as virtual columns that arent physically stored in the
table, and their values are recalculated every time theyre referenced in a query. However, you
can use the PERSISTED keyword in the CREATE TABLE and ALTER TABLE statements
to require SQL Server 2005 to physically store computed columns in the table. When that
happens, the computed column values are updated when any columns that are part of their
calculation change.
Computed columns can be used in select lists, WHERE clauses, ORDER BY clauses, or any
other locations in which regular expressions can be used.
You must always persist computed columns in the following cases:
The computed column is used as a partitioning column of a partitioned table.
The computed column references a Common Language Runtime (CLR) function. In
this case, the computed column must be persisted so that indexes can be created on it.
The computed column is used as a check, foreign-key, or not-null constraint.
Designing Filegroups
THE BOTTOM LINE
Database objects, such as tables, indexes, views, and files, can be grouped together in
filegroups for allocation and administration purposes. There are two types of filegroups:
primary and user-defined.
The primary filegroup contains the primary data file and any other files not specifically
assigned to another filegroup. All pages for the system tables are allocated in the primary
filegroup. User-defined filegroups are any filegroups specified by using the FILEGROUP
keyword in a CREATE DATABASE or ALTER DATABASE statement.
TAKE NOTE
Log files are never part of a filegroup. Log space is managed separately from data space.
No file can be a member of more than one filegroup. Tables, indexes, and large object data
can be associated with a specified filegroup, and all their pages are allocated in that filegroup.
Alternatively, the tables and indexes can be partitioned. In that case, the data of partitioned
tables and indexes is divided into units, each of which can be placed in a separate filegroup.
One filegroup in each database is designated the default filegroup. When a table or index is
created without specifying a filegroup, its assumed that all pages will be allocated from the
default filegroup. Only one filegroup at a time can be the default filegroup. Members of the
db_owner fixed database role can switch the default filegroup from one filegroup to another.
If no default filegroup is specified, the primary filegroup is the default filegroup.
For example, suppose you have a sales database with several tables. Some of the tables are
mostly static, whereas others are volatile and frequently written to. If all these tables are
placed in the same filegroup, you have no control over the file in which theyre placed.
However, if you place a secondary data file on a separate physical hard disk (for example, disk D)
and place another secondary data file on another physical hard disk (disk E, perhaps), you can
place each data file in its own filegroup. This gives you control over where objects are created.
In this case, the best option is to place the first secondary data file by itself in a filegroup
named READ and to place the second secondary data file in its own filegroup named
WRITE. Now, when you create a table that is meant to be primarily read from, you can tell
SQL Server to create it on the file in the READ group, and you can place tables that are
meant to be written to in the WRITE filegroup.
TAKE NOTE
As you learned in Lesson 2, secondary data files make up all the data files other than the
primary data file. Some databases may not have any secondary data files, whereas others
have several secondary data files.
Using files and filegroups improves database performance, because it lets a database be created
across multiple disks, multiple disk controllers, or RAID systems. For example, if your computer has four disks, you can create a database that is made up of three data files and one log
file, with one file on each disk. As data is accessed, four read/write heads can access the data
in parallel at the same time. This speeds up database operations.
Additionally, files and filegroups enable data placement, because a table can be created in
a specific filegroup. This improves performance because all I/O for a specific table can be
directed at a specific disk. For example, a heavily used table can be put on one file in one
filegroup, located on one disk, and the other less heavily accessed tables in the database can be
put on the other files in another filegroup, located on a second disk.
184 | Lesson 8
REF
In SQL Server 2005 and 2008, databases made up of multiple filegroups can be restored
in stages by a process known as piecemeal restore.
When multiple filegroups are used, the files in a database can be backed up and restored individually. Under the simple recovery model, file backups are allowed only for read-only files.
Using file backups can increase the speed of recovery by letting you restore only damaged files
without restoring the rest of the database. For example, if a database is made up of several
files physically located on different disks, and one disk fails, then only the file on the failed
disk has to be restored.
REF
In a database design, an index is an on-disk structure associated with a table or view that
speeds retrieval of rows from the table or view. An index contains keys built from one
or more columns in the table or view. These keys are stored in a structure (B-Tree) that
enables SQL Server to find the row or rows associated with the key values quickly and
efficiently.
If you wanted to find the topic filegroup in this book, how would you go about it? You could
flip through pages one at a time, looking for the word filegroups or you might examine the
table of contents at the front of the book. Both these methods work, but they arent efficient.
Instead, youd probably flip to the back of the book and review the index for the word
filegroup. If the index is well constructed, it will contain several entries and probably some
subheadings to help you differentiate the topic.
Two types of indexes are associated with a table or a view: clustered and nonclustered.
Clustered indexes sort and store the data rows in the table or view based on their key values.
These are the columns included in the index definition. There can be only one clustered
index per table because the data rows can be sorted in only one order.
The data rows in a table are stored in sorted order only when the table contains a clustered
index. When a table has a clustered index, the table is called a clustered table. If a table has no
clustered index, its data rows are stored in an unordered structure called a heap.
Nonclustered indexes have a structure separate from the data rows. A nonclustered index
contains the nonclustered index key values, and each key value entry has a pointer to the data
row that contains the key value.
Table 8-1 shows the differences between clustered and nonclustered indexes.
TAKE NOTE
C LUSTERED
NONCLUSTERED
You can have only one clustered index per table because clustered indexes physically
rearrange the data in the indexed table.
Which type of index should you use, and where? In a few moments, youll look at how you
can design indexes for faster data access and how to perform data modification. First, examine
some basic guidelines and strategies you should employ when designing indexes.
The first consideration is making sure you understand the characteristics of the database.
For example, is it an On-Line Transaction Processing (OLTP) database with frequent data
modifications, or a Decision Support System (DSS) or data-warehousing (On-Line Analytical
Processing [OLAP]) database that contains primarily read-only data?
Next, what are the characteristics of the most frequently used queries? For example, knowing
that a frequently used query joins two or more tables will help you determine the best type of
indexes to use.
You should also have a clear idea of the characteristics of the columns used in the queries.
For example, an index is ideal for columns that have an integer datatype and are also unique
or non-null.
Determine which index options may enhance performance when the index is created or
maintained. For example, creating a clustered index on an existing large table will benefit
from the ONLINE index option. The ONLINE option allows for concurrent activity on the
underlying data to continue while the index is being created or rebuilt.
Finally, make sure you give thought to the optimal storage location for your indexes.
186 | Lesson 8
Indexing small tables may not be worthwhile, especially if it takes the Query Optimizer
longer to traverse the index searching for data than performing a simple table scan
would. Although the indexes on small tables may never by used, they must still be maintained as data in the table changes, thus slowing performance and retarding data modification with unnecessary resource usage.
Indexes on views can provide significant performance gains when the view contains
aggregations, table joins, or a combination of aggregations and joins. The view doesnt
have to be explicitly referenced in the query for the Query Optimizer to use it.
Use the Database Tuning Advisor to analyze your database and make index
recommendations.
LAB EXERCISE
When you use Profiler, you generally save all the monitored events to a file on disk. This file
is called a workload, without which the Database Tuning Advisor cant function. To create the
workload, you need to run a trace (which is the process of monitoring) to capture standard
user traffic throughout the busy part of the day.
In Exercise 8.4, youll walk through the process of using Database Tuning Advisor to create an
index.
Once your indexes have been created, they should be maintained on a regular basis to make
certain theyre working properly.
Storing a nonclustered index on a filegroup that is on a different disk than the table filegroup improves performance because multiple disks can be read at the same time.
Clustered and nonclustered indexes can use a partition scheme across multiple filegroups. When you consider partitioning, determine whether the index should be
alignedthat is, partitioned in essentially the same manner as the tableor partitioned
independently.
Create nonclustered indexes on a filegroup other than the filegroup of the base table.
This will result in performance gains if the filegroups are using different physical drives
with their own controllers.
Partition clustered and nonclustered indexes to span multiple filegroups.
Because you cant predict what type of access will occur and when it will occur, it may be
better to spread your tables and indexes across all filegroups. Doing so guarantees that all
disks are being accessed, because all data and indexes are spread evenly across all disks,
regardless of which way the data is accessed. This is also a simpler approach for system
administrators.
Designing Views
THE BOTTOM LINE
A view is nothing more than a virtual table whose contents are defined by a query. A view
is the filter through which you look at one or more columns from one or more base tables.
In the real world, many companies have extremely large tables that contain hundreds of
thousands, if not millions, of records. When your users query such large tables, they usually
dont want to see all of these millions of records; they want to see only a small portion, or
subset, of the available data. You have two ways to return a small subset of data: You can use a
SELECT query with the WHERE clause specified, or you can use a view.
The SELECT query approach works well for queries that are executed infrequently, but this
approach can be confusing for users who dont understand T-SQL code. For example, to
query the AdventureWorks database to see only the first-name, last-name, and phone fields
for contacts in Connecticuts 203 area code, you can execute the following query:
USE AdventureWorks
SELECT Lastname, Firstname, Phone FROM Person.Contact
WHERE phone LIKE '203%'
That query returns a small subset of the data; but how many of your end users understand
the code required to get this information? Probably very few. You can write the query into
your front-end code, which is the display that your users see (usually in C# or a similar
language); but then the query will be sent over the network to the server every time its
accessed, and that eats up network bandwidth.
The best approach in this sort of a situation is to create a view for the users. Like a real table,
a view consists of a set of named columns and rows of data. The only difference between the
view and the table is that your view doesnt contain any datait shows the data, much like
the television set doesnt contain any people, but just shows you pictures of the people in the
studio.
Unless its indexed, a view doesnt exist as a stored set of data values in a database. The rows
and columns of data come from tables referenced in the query defining the view and are
produced dynamically when the view is referenced.
Now that you have a basic understanding of views, look at how to integrate them in to your
physical database design.
188 | Lesson 8
Standard views. Combining data from one or more tables through a standard view lets you
satisfy most of the benefits of using views. These include focusing on specific data and simplifying data manipulation.
Indexed views. An indexed view is a view that has been materialized. This means it has been
computed and stored. You index a view by creating a unique clustered index on it. Indexed
views dramatically improve the performance of some types of queries. Such views work best
for queries that aggregate many rows. They arent well-suited for underlying data tables that
are frequently updated.
Indexed views typically dont improve the performance of the following types of queries:
Partitioned views. A partitioned view joins horizontally partitioned data from a set of
member tables across one or more servers. As you learned, this has the effect of making the
data appear to the user as if theyre one table. A view that joins member tables on the same
instance of SQL Server is a local partitioned view.
A view that joins data from tables across servers is called a distributed partitioned view.
Distributed partitioned views are used to implement a federation of database servers (which
is not part of the Star Trek universe). A federation of database servers (FDS) is a group of
independently administered servers that cooperate to share the processing load of a system. By
partitioning data, you can create an FDS, which lets you scale out a set of servers to support
the processing requirements of large, multitiered Web sites.
S K I L L S U M M A RY
The principal building block of any database infrastructure design, the physical database, has
been the focus of this Lesson, and its mastery has required us to go through quite a bit of
material. First you learned that a database is a container for other objects, such as tables
and views, and that without databases to contain all these objects, your data would be a
hopeless mess.
You learned that a database consists of up to three kinds of files: primary data files, secondary
data files, and transaction log files. The primary data files are used to store user data and
system objects that SQL Server needs to access your database. The secondary data files store
only user information and are used to expand your database across multiple physical hard
disks. The transaction log files are used for up-to-the-minute recoverability by keeping track of
all data modifications made on the system before theyre written to the data files.
You were also introduced to the value of normalization and when to selectively allow
denormalization for performance purposes. You learned how to use SQL Server scripts to
document a database and how to use the Database Diagram Designer to diagram it.
You have learned that you should sit down with a pencil and paper and think about how the
tables will be laid out before you create them, and that you need to decide what the tables
will contain, making the tables as specific as possible. You also learned that tables are made
up of fields or columns (which contain a specific type of data) and rows (an entity in the
table that spans all fields). Each column in the table has a specific datatype that restricts the
type of data it can holda field with an int datatype cant hold character data, for example.
Then you found you can create your own datatypes, which are system datatypes with all the
required parameters presupplied.
Tables are open to just about any kind of data when theyre first created. The only restriction
is that users cant violate the datatype of a column. To restrict the data your users can enter
in a column, you learned how to enforce three types of integrity domain, entity, and
referentialthrough check, default, and unique constraints, as well as primary and
foreign keys.
Youve learned how using files and filegroups improves database performance, because it lets
a database be created across multiple disks, multiple disk controllers, or RAID systems.
Data access can be accelerated by using indexes at the expense of slowing data entry.
You first looked at the clustered index. This type of index physically rearranges the data
in the database file. This property makes the clustered index ideal for columns that are
constantly being searched for ranges of data and that have low selectivity, meaning
several duplicate values.
Nonclustered indexes dont physically rearrange the data in the database; rather, they create
pointers to the actual data. This type of index is best suited to high-selectivity tables (with few
duplicate values) where single records are desired rather than ranges.
190 | Lesson 8
You also learned to design indexes by using the Database Tuning Advisor, a tool designed to
take the stress of planning the index off you and place it on SQL Server. This knowledge of
indexing will make it easier for you to plan indexes so that you can speed up data access for
your users.
Views dont contain any dataits just another means of seeing the data in the underlying,
base table. You also learned about the three types of views and when to use them, and how
to filter data in a view.
For the Certification Examination:
Be familiar with normalization and denormalization. Its important that you know why
databases are normalized and when you should opt to selectively denormalize a database.
Pay particular attention to the performance parameters that dictate when these need to
be done.
Know how to document and diagram a database. Make sure you understand the uses of
the Script As process for creating a SQL script of a database object and how to use the
Database Diagram Designer.
Be familiar with partitioning. Partitioning is a feature introduced in SQL Server 2005. Its
role in performance enhancement, especially over multiple databases, is critical.
Understand constraints and keys. Make sure you know how primary and foreign keys
function, as well as check, default, and unique constraints. You should be familiar with the
best situation in which to use each.
Understand filegroups. Filegroups are a key method for maximizing SQL Server database
performance. You should be familiar with the performance enhancement they offer and
their restrictions and limitations.
Understand indexes. You should know the basic differences between the types of indexes.
Understand views. You should know that the purpose of a view is to focus data for users.
Know the three different types of views and when to use them.
Knowledge Assessment
Case Study
Trevallyn Travel
Trevallyn Travel provides a variety of travel services. It has nine storefront agencies in
six North American cities, with its main office in New York. The company also serves
worldwide customers through an online travel agency.
Planned Changes
Trevallyn Travel plans to upgrade all existing SQL Server computers to SQL Server
2005. The management of the company wants a complete review of the existing
physical database design infrastructure to ensure that its aligned with business
requirements and optimizes performance.
S ERVER N AME
D ATABASE N AME
S IZE
D ESCRIPTION
Launceston
HR
500 MB
Devonport
Storefront
4 GB
Hobart
OnLine-ReadOnly
6 GB
10 GB
Ravenwood
Travel-OnLine
The Storefront database is accessed though a Visual Basic application. The TravelOnLine
and OnLineReadOnly databases are accessed through a web services application.
Existing Infrastructure
The TravelOnLine and Storefront databases are mission critical. The current backup
strategy includes nightly full backups, hourly transaction-log backups, and the bulklogged recovery model.
System databases are maintained on a hard disk set that is separate from the user
databases.
Business Requirements
The TravelOnLine database is the busiest and should be optimized accordingly.
In the Reservation table in the Storefront database, reservations that were made in
the last six months should be retrieved the fastest.
The distribution server has a large amount of free disk space. The distribution
database must be able to be restored from the most recent backup and then receive
changes from the publication database, allowing replication to continue.
A single drive failure should not cause a server to fail.
The TravelOnLine database has a table named Pax, which holds passenger information.
(Pax is travel-agent jargon for passenger.) Any optimization that occurs on the table
should not affect current indexes. The table contains the following columns:
PaxID
PaxName
Address
City
Region
PostalCode
Phone
PreferredAirline
The most common query to this table looks up the passengers name.
Reservation records in the TravelOnLine database have a status field that can have one
of three settings: 1 (received), 2 (in process), or 3 (completed). Users can retrieve and
update incomplete reservations through a view, but they must not be able to complete
orders through the view.
192 | Lesson 8
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions:
1. You need to define the datatype for a new column named MeritScore in the HR
database. Which option should you select?
a. Use the text datatype.
b. Use the nvarchar(max) datatype.
c. Use the vchar(max) datatype.
d. Set the large value.
2. You need to make recommendations for maximizing the performance of queries based
on passenger names from the Pax table. What do you recommend?
a. Create an index on the passenger name and ID columns. Set the index fill factors at
10 percent.
b. Create a nonclustered index on only the passenger name column.
c. Create a clustered index on the passenger name column.
d. Create a nonclustered index, using the INCLUDE clause for all columns, on the
passenger name column.
3. Query performance on the Reservation table of the TravelOnLine database is less than
optimal. As a solution, you decide to partition the table so that queries on the current
and future reservations are quickly returned. Which of the following is the best choice
for the partition column?
a. Reservation date column
b. Reservation status column
c. Reservation airline column
d. Reservation agent column
4. You have two tables in the HR database, HR.EmployeeName and HR.EmployeeAddress,
with columns as follows:
HR.E MPLOYEE N AME
HR.EMPLOYEEADDRESS
EmployeeID
AddressID
LastName
EmployeeID
FirstName
Street
Title
City
ZipCode
City
State
Based on the previous information, which is the best choice to be a foreign key?
a. City column in HR.EmployeeName
b. City column in HR.EmployeeAddress
c. EmployeeID in HR. EmployeeName
d. EmployeeID in HR.EmployeeAddress
5. You have been told that the MeritIncrease column should be configured so that no
employee receives less than a 2 percent merit increase and no one receives more than an
8 percent increase. What do you do?
a. Create a default constraint set to 2 percent.
b. Create a check constraint that allows for data ranging from 28 percent.
c. Create a foreign key relationship between MeritIncrease and Salary.
d. Create a unique constraint.
6. Under what circumstances must a computed column be persisted? (Choose all that
apply.)
a. The computed column is used as a partitioning column of a partitioned table.
b. The column references a CLR.
c. The computed column is used as a primary key.
d. The computed column is used a check constraint.
7. Which of the following are true about the differences between clustered and
nonclustered indexes? (Choose all that apply.)
a. Up to 249 clustered indexes are allowed per table.
b. Nonclustered indexes are designed for columns that are searched for single values.
c. Clustered indexes are best used on columns with low selectivity.
d. Both physically rearrange the data in the table to conform to their constraints.
8. You decide to create a view of the OnLineReadOnly database to show the current reservation status based on passenger name. The view joins tables from across servers. This is
an example of what kind of view?
a. Partitioned view
b. Standard view
c. Indexed view
d. Constrained view
9. Which of the following effects does normalizing a database object, such as a database or
table, have on indexing?
a. Faster sorting and index creation
b. Large number of clustered indexes
c. Narrower and more compact indexes
d. All of the above
10. You have two tables in the HR database, HR.EmployeeName and HR.EmployeeAddress,
with columns as follows:
HR.E MPLOYEE N AME
HR.EMPLOYEEADDRESS
EmployeeID
AddressID
LastName
EmployeeID
FirstName
Street
Title
City
ZipCode
City
State
You need to ensure that there are no duplicate values in the Social Security Number
field. How should you do that?
a. Add a default constraint to the field.
b. Add a unique constraint to the field.
c. Make the Social Security Number field a primary key.
d. Make the Social Security Number field a foreign key.
Creating Database
Conventions and
Standards
LESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
EXAM OBJECTIVE
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
camelCase: A method or
standard for naming objects.
With camelCase, all characters
are lowercased except the first
letter of component words
other than the first word. An
example of camelCase would be:
customerAddress.
convention: A convention is a set
of agreed, stipulated, or generally
194
If you have any experience with databases, the need for and value of naming conventions,
particularly in an enterprise setting, should be both self-evident and axiomatic. In fact,
you may wonder why this book needs to have a Lesson on the obvious. If you have little
or no background, then you may consider this Lesson a primer in becoming a punctilious
nitpicker with a tendency toward anal retentiveness and rigidity of thought. You may also
want to know, Whats the big deal about how things are named and what standards are
applied? The results are all thats important.
The answer is simple. Having database conventions and standards offers a method of
organizing the server infrastructure as well as increasing productivity and the effectiveness
of the database administrator and development teams. Good standards that are consistently
applied grow in usefulness over time because they help make even unfamiliar databases easier
to understand. Because its unlikely that youll be working alone, devising and creating database conventions and standards should be a team effort. The standards should be good, workable, and something your team members agree with.
Finally, although its easy to think up naming conventions and coding standards, they must
be durable enough to survive changing circumstances. Its difficult to modify conventions and
standards and apply them retrospectively to existing databases because of the impact doing
so can have on applications and security. Flexibility and the ability to adapt to changing (and
unforeseen) circumstances for standards and conventions are crucial to how successful they
are. A good example in the non-IT world is the U.S. Constitution. A mere four pages long,
its both the shortest and longest-lasting constitution in the world. The genius to its longevity
and effectiveness is its flexibility and ability to adapt to circumstances not even dreamt of by
its original authors.
When designed correctly, a database naming convention lets database developers and
administrators easily identify the type and purpose of any object in a database system.
Its important to create a consistent and meaningful naming convention for a database server
infrastructure. Applying a single, consistent standard for the entire infrastructure, even if you
have to implement it in steps, will reduce the time and associated costs when developers start
using a new database. It will also simplify the task of managing a larger number of databases.
TAKE NOTE
Database naming conventions are typically product specific. What constitutes a valid name
or good practice in one database management system may be invalid or bad practice in
another. If youre using SQL Server with other database management systems, youll
probably need to create a naming convention that spans each system. Similarly, if youre
migrating from a different database management system to SQL Server, youll likely need
to adapt the names used by migrated objects to conform to SQL Server best practices.
196 | Lesson 9
Despite the tangible benefits of naming conventions, there are still those who think that the
need to establish them doesnt apply to their circumstances. The arguments tend to fall into a
couple of categories:
Our team (or the company) is small, so adopting and enforcing a naming convention
is unnecessary administrative overhead. The problem with this argument is that the
smallness of the organization is what calls for a naming convention. Without such a
convention, dependencies on particular team members are likely to develop. Similarly,
depending on an individuals memory means youll inevitably lose some critical knowledge if a team member moves on. Naming conventions and standards can minimize
that loss.
There isnt time for new team members to learn current conventions. This is a false
economy usually argued for by a shortsighted manager. There is an old proverb, Give a
man a fish, and he eats for a day; teach him to fish, and he eats for a lifetime. By applying the proverb here, the time spent understanding how a naming convention works can
save considerable time later.
TAKE NOTE
When faced with existing database objects that are poorly named but cant be renamed, you
can use synonyms as alternate names that are more descriptive. For example, if you have a
table named OrdNm that holds order name data, you should consider defining a synonym
called OrderName. You can then reference the table through this synonym until you can
rename the table.
D ATABASE
O BJECT
CONVENTION
Tables
Tables typically represent entities such as Customer or Order. Its best to use
the name of the entity that the table represents for the name of the table
because the name should be both accurate and descriptive. Use singular
names whenever possible.
Columns
Columns describe attribute data values, and you should try to retain the
same meaningful name for each column in the database. For example,
use LastName for a column holding the last name of an employee in the
Employee table. Using descriptive names makes your SQL code more readable.
Views
Stored
procedures
Stored procedures express actions. You should use a meaningful name combining verbs and objects that describe their action. To avoid confusion with
system-stored procedures, dont use the sp_ prefix; consider using usp instead.
User-defined
functions
User-defined functions calculate values. As with stored procedures, use meaningful names that describe the calculations the functions perform. A common
convention is to prefix the name with ufn to distinguish user-defined functions from columns or views in SQL statements. For example, ufnCalculateSalesTaxDue could be the name of a user-defined function that calculates the
sales tax due for a transaction.
Triggers
Indexes
Index names commonly combine the name of the table and the names of the
columns, and they frequently include a prefix such as IX_. For example, the
index IX_Employee_ManagerID column might span the ManagerID column in
the Employee table. You can augment the prefix to indicate whether the index
is clustered or nonclustered, a unique index, and so on. An advantage is that
the index names become self-documenting. However, this approach can result
in lengthy names. Normally this isnt a problem because youre unlikely to
refer directly to the name of an index in your applications or SQL commands.
Constraints
Schemas
198 | Lesson 9
CERTIFICATION READY?
Make sure you know
where SQL Server looks
for stored procedures
and the search order.
The biggest problem with following this convention is the maintenance cost. For example
when you change a columns datatype, you have to change the column name or else invalidate
the convention. Keeping up with this purely arbitrary naming convention adds no valuea
clear case of the juice not being worth the squeeze.
Using short or abbreviated object names
There is no reason to stick to obscure and cryptic short names any longer. The point of naming something is to identify it, not cause you to play a guessing game.
Using reserved words as object names
This is not only bad practice, but also rife with possible disaster. Using reserved words for
object names means that you constantly have to delimit identifiers with square brackets or
double quote marks. This makes your code difficult to read, and again, for no good reason.
The possibility also increases that the now-difficult-to-maintain SQL commands may fail.
LAB EXERCISE
200 | Lesson 9
Just as you need to establish naming conventions, you need clearly defined database
standards. These standards cover T-SQL coding, database access, and change deployment.
In this section, youll examine the why and how of database standards and learn some basic
ways of creating and managing standards.
Ironically, the need for standards is an inevitable result of the flexible and freewheeling way in
which development has grown. As software developers created more and better database programs,
with maximum flexibility and an open invitation to innovate, they sowed the seeds of confusion.
Developers can now use many different techniques for accessing databases. They can document their code in a number of different ways (assuming they document it at all). At the same
time, different teams can deploy databases and applications to the production environment in
a variety of ways. The problem with all this creativity and inventiveness is that it has unleashed
a form of documentation anarchy. When different developers and teams follow their own
individual practices, they can end up creating code and databases that are difficult to maintain.
Similarly, letting different groups deploy applications and databases in uncontrolled ways can
lead to chaos, possibly resulting in security failure, if not complete system breakdown.
Having no infrastructure standardsor, worse, having them and not enforcing themis an
invitation to inconsistent behavior in the database and its application as well as development
of old-fashioned, poor-quality applications.
A key activity in designing your infrastructure must include database standards that are
clear, sensible, and enforced. Defining and using standards will alleviate many problems and
provide a number of benefits. For example, if you require developers to follow a standard
technique for accessing and manipulating databases, the result should be code that a different developer can maintain with a minimal learning curve. At the same time, youll be more
confident of the quality of the applications being built.
In addition, defining database standards can help your team, department, or organization operate more systematically and can reduce the time it takes to learn new systems or move from one
system to another. Defining a standard process for deploying databases and database applications
reduces the scope for errors, minimizing the likelihood of system failure and security breaches.
Any list of database infrastructure standards is necessarily incomplete because every organization has its own unique needs. As with naming conventions, database infrastructure standards
tend to be developed or enhanced by the organization that uses them, so there is no such
thing as an exhaustive list.
However, there are general standards that are nearly universal. The following sections describe
the types of standards you should consider defining.
LAB EXERCISE
Use templates for each type of object, such as stored procedures, user-defined functions,
views, and triggers. The templates usually contain predefined code that guides developers
through the items they should implement. Templates can also contain boilerplate areas
for descriptions, the author, the date of creation, and a log of changes and reasons for
the changes.
Adopt the following stylistic standards:
Prefix every reference to a database object with the name of the schema it belongs to.
Indent every block of code appropriately.
Use uppercase letters for all SQL and SQL Server keywords.
Apply the following functional standards to database code objects, whether based on TSQL or managed code:
Ensure that code in triggers can handle multiple inserts, updates, or deletes, not just a
single row.
Never use T-SQL user-defined functions (UDFs) to perform searches on other tables by
executing a lookup for some value based on a key. This use of UDFs can result in poor
performance if a UDF is used as part of a SELECT query that returns many records.
Avoid using cursors inside stored procedures. Cursors are exceptionally poor replacements for set-based queries and should be used only when absolutely required.
Require that stored procedures avoid creating and using temporary tables unless they
improve performance.
Employ TRY . . . CATCH constructs to perform error handling. This helps simplify the
logic of a T-SQL block and avoids the use of @@ERROR functions in repeated tests.
In Exercise 9.2, youll use Template Explorer to use an existing template for T-SQL code.
202 | Lesson 9
Another reason to develop database access standards is that when applications access databases
in a wide variety of nonstandard ways, it becomes much more difficult to optimize systems,
trace connections when identifying performance problems, and enforce security best practices.
The lack of a data access standard can also needlessly increase the complexity of the deployment process, adding an unnecessary level of fragility to an application (and the database).
Prudence dictates that, as with most infrastructure activities, you should develop a set of standards or rules for accessing databases that you can apply to your entire infrastructure.
The first question you should consider is whether you want to allow users and applications to
access the data in a database directly or only indirectly.
available in a stored procedure. To compensate, you would need to place more of the logic in
client applicationsnot necessarily the best approach.
204 | Lesson 9
before sending them back for testing. When testing has been completed, the same scripts are
then used to build or update the production environment.
To ensure the validity of the development and test environments, its most efficient to build
the development and test databases from backups of the production database (making sure
to protect or remove any sensitive data if applicable). You should utilize a source-control system to maintain the latest versions of table schemas, stored procedures, and all database code
objects. The database source code should be versioned and labeled following the style adopted
for the overall application development project. Save all deployment scripts, including those
implementing schema changes and data modifications, in the same source-control system.
REF
Its best to keep your run book as a document in your source-control tool, so that you have
access to all versions.
REF
Database security is an extensive and important topic. Setting standards for database
security can help reduce that complexity across your entire infrastructure. For example,
you may decide to require that all users log in to SQL Server by using Microsoft
Windows authentication, thereby enforcing the same level of security for database users
as at the network level. Although you should be aware of the need to set database security standards, detailed discussion is beyond the scope of this lesson.
S K I L L S U M M A RY
In this lesson, you learned about the importance of naming conventions and database control
standards as part of an effective infrastructure. You learned how to design a flexible naming
convention system that maximizes effectiveness. You learned naming convention best practices.
You also read about bad naming practices and how to avoid them. If youve ever questioned
the value of a naming convention system, that doubt has been laid to rest.
You also learned that a naming convention system that is inflexible is as valueless as one that
doesnt exist. You reviewed some methods, such as synonyms, for dealing with existing databases
that have no or poor naming conventions.
You examined how defining database standards can help your team, department, or organization
operate more systematically and reduce the time it takes to learn new systems or to move from
one system to another. You learned techniques for defining standard processes to deploy databases and database applications and how doing so minimizes the chance for errors and potential
of system failure and security breaches. You learned about run books and how to use them when
deploying and maintaining your databases and applications.
You also read about best practices for coding and database access standards and how they
integrate with the security standards that you learned about in other Lessons.
For the certification examination:
Understand the benefits of naming conventions. Its important to know how naming
conventions work and how to develop a flexible set of naming standards.
Understand the common bad naming practices. Just as its important to know what a
good naming convention is, you should also know the most typical errors and how to
avoid them.
Be familiar with T-SQL coding standards. Understand what makes a good T-SQL code
standard, what common errors to avoid, and how to use Template Explorer to minimize
the risk of error.
Be familiar with database access standards. Understand the best practices for database
access and how to define them as standards.
Be familiar with database deployment standards. Understand the best practices for database
deployment and how to define them as standards. Understand how to plan deployment.
Make sure you understand the value of assigning roles and how to do so effectively. You
should also be aware of the various functions of development, test, and production servers
and how and when to use them. Be aware of how to protect data during deployment or
changes, as well as when and how to plan rollbacks in the event of a deployment failure.
206 | Lesson 9
Knowledge Assessment
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
1. Which of the following are benefits of having database naming conventions? (Choose all
that apply. )
a. Provides a method to organize infrastructure
b. Reduces the learning curve for new database administrators
c. Makes coding easier
d. All of the above
2. Which of the following are the most important attributes of a naming convention?
(Choose all that apply.)
a. Flexibility
b. Regulatory requirements
c. Consistency
d. Size of the organization
3. Which of the following database objects should have a naming convention? (Choose all
that apply.)
a. Database
b. Table
c. Trigger
d. Index
4. Which of the following practices should not be followed?
a. Prefixing a view with vw_
b. Prefixing a stored procedure with sp_
c. Using prefixes with schema
d. Using the prefix ufn to define a user-defined function
5. Which of the following are good naming practices for indexes? (Choose all that apply.)
a. Combine the name of the table and the names of the columns.
b. Specify whether the index is clustered or nonclustered.
c. Include a prefix such as IX_.
d. Use spaces to separate key elements.
6. When you have an existing database with poorly named objects that cannot be renamed,
what is the best way improve clarity of the naming conventions?
a. Use a lookup table.
b. Create a new column.
c. Note in your standards documentation what the poorly named object actually
represents.
d. Use a synonym.
7. Which of the following is not a bad practice for naming conventions?
a. Using the sp_ prefix in user-defined stored procedure names
b. Inconsistent use of uppercase and lowercase letters
c. Using numbers in the name
d. Using reserved words for object names
8. Which of the following are not recommended names for tables in a SQL Server
database? (Choose all that apply.)
a. Person.Address
b. Person.Address Type
c. tbl_Person.AddressType
d. dbo.MSmerge_history
208 | Lesson 9
16. Which of the following are good deployment practices? (Choose all that apply.)
a. Require developers to use the test rather than the production database.
b. Do a complete backup of the production database before applying changes.
c. Utilize a source-control system to maintain the latest versions of table schemas, stored
procedures, and all database code objects.
d. Allow only production database administrators to access the production database.
17. What must be in place prior to initiating a deployment from test to production?
(Choose all that apply.)
a. Backup of the development database
b. Definition of roles and responsibilities of staff involved
c. Sequence of steps to follow
d. Rollback plan
18. What should you use to log all actions taken by a database administrator that affect a
production database?
a. Transaction log
b. Shipping log
c. Desk calendar
d. Run book
19. The word NewYorkYankees is an example of what style of casing?
a. Hungarian case
b. Reverse Polish case
c. camelCase
d. PascalCase
20. Which of the following methods and tools can you use to ensure proper dissemination of
documentation regarding naming conventions, coding standards, rollback plans, deployment sequence, and other control procedures and standards? (Choose all that apply.)
a. Network share
b. Intranet site
c. SharePoint Portal Service
d. All of the above
Designing a SQL
Server Solution for
High Availability
L ESSON
10
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
(continued )
209
210 | Lesson 10
L E S S O N S K I L L M A T R I X (continued )
TECHNOLOGY SKILL
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
database mirroring: A
technology for continuously
copying all data in a database
from one server to another
so that in the event that the
principal server fails, the
secondary server can take over
the processing of transactions
using its copy of the database.
failover: A switch between the
active and standby duplicated
systems that occurs automatically
without manual intervention.
Sometimes known as switchover.
high availability: The continuous
operation of systems. For a
system to be available, all
components including application
and database servers, storage
devices, and the end-to-end
network need to provide
uninterrupted service.
log shipping: A technology for
high availability that is based on
the normal backup and restore
procedures that exist with SQL
Server. In this environment,
transaction-log backups are made
A highly tuned, efficiently designed, well-configured database is of no use if it isnt available. The past few years have seen some huge disasters across the world, from the tsunami
in the Indian Ocean to Hurricane Katrina in the United States. Each of these has taken
its toll in many ways, many more severe than the continued availability of your database
server. However, these disasters have brought to the forefront the need to ensure that
your computer systems can survive and continue to function in the face of issues with
the primary server.
As SQL Server has matured as a product, increasing numbers of people have called for better
solutions for ensuring their databases are highly available. Microsoft has responded, expanding
the capabilities of SQL Server in this area with each version. With SQL Server 2005, there are
not only more solutions but also solutions that are easier to implement and administer.
The holy grail of availability measurements is the five nines, which corresponds to an uptime
or availability of 99.999 percent. This equates to a yearly downtime of five minutesbarely
enough time for a reboot on most servers.
Although a single server probably cant achieve this level of availability for any appreciable length
of time, using two or more servers with a technology to move data, connections, and the other
parts of a SQL Server application to another server can help you get to this level of reliability.
This Lesson looks at the four main technologies used in SQL Server solutions to achieve a
highly available database server.
SQL Server incorporates four technologies to enable you to build a highly available solution:
clustering, database mirroring, log shipping, and replication.
Before looking at any particular high-availability solution, you should first examine the goals
of a highly available system. There are some common misperceptions as to what benefits and
capabilities a high-availability (HA) designed system brings to a particular company. As with
any technical solution, the choice of which HA technology to choose should ensure that the
business requirements for availability and cost are met.
212 | Lesson 10
Network connection. Most laptops have a single network interface card (NIC) and
a single path to connect to the network, so the NIC, cable, or switch can crash your
system.
Windows 2003. Until you implement some type of HA technology, the Windows
operating system host is a single point of failure.
SQL Server and the application. The software components of your system, subject to
patching and changes, can fail, resulting in a system crash.
You could have a single point of failure in other places, but these are the primary ones. Some
of these can be mitigatedarguably, all of them, with a technology such as clustering. Some
components (for example, the built-in laptop mouse) might cause problems if they failed but
probably wouldnt crash the system. If however you were unable to make take critical actions
due to the simple mouse failure, you have the risk that a small minor failure could facilitate
more significant problems.
The key goal of your HA system design is to eliminate as many single points of failure as
possible. This usually means designing redundant parts into the system, such as RAID drive
arrays, spare power supplies, and so on; but it can also include developing a plan for alternate
ways of running the system in the event of a disaster.
In designing your HA system, you must examine all the components, down to the cables that
connect the systems, and assess the impact of any particular piece of equipment failing. In
building the HA system, you should have a way to mitigate any of these failurespreferably,
an automated response.
You should also think creatively about related parts of your system. Consider patches and
upgrades, staff, vendor resources (such as your Internet connection), and more to ensure that
every part of the system, from server to client, has as few single points of failure as possible.
An HA system is often
referred to as having no
single point of failure,
meaning that any one
component that fails
wont affect the ability
of the database server
to function.
In setting your goals, be sure youre meeting the needs of your organization and not just
building an HA system focused on uptime. The cost of the solution, whether automatic or
manual failover is required, and the impact on the finances of the company based on ROI are
all factors that should be incorporated into your design goals.
The machine that provides the services that SQL Server offersaccess to data, messaging
queues, and so onis generally referred to as the principal server. This is the Windows host
that is running SQL Server and to which the clients connect. Any servers that are set up and
ready to take over the services in the event of a disaster are called secondary servers.
A disaster in this context is any event that causes an interruption of service by the primary SQL
Server machine. This could be something as minor as a power cord that becomes unplugged,
as major as a hurricane that destroys the data center, or anything in between. Whatever event
occurs, its classified as a disaster for the primary SQL Server, and the HA solution chosen is
used to bring a secondary server online and allow clients to access the data on this server.
The event of moving the service from the primary server to a secondary server is called
a failover. This can be automatic or manual and doesnt necessarily imply a disaster has
occurred. Often, a failover is forced to occur in some situations, such as when patches are
applied, to minimize the downtime of the database.
Some of the technologies provide for an automatic failover of the SQL Server service to
another machine in the event of a disaster occurring on the primary machine. Others require
a manual intervention, with an administrator performing an action to bring the secondary
database online. No matter which solution you choose, there will be a delay as the secondary
server comes online, during which the database will be inaccessible. This delay and its
frequency affects the amount of uptime youll be able to achieve.
Each HA technology has advantages and disadvantages. Table 10-1 lists a few of the characteristics of each technology. These characteristics will affect your choice of an HA solution in
your environment.
Table 10-1
High-availability comparison
T ECHNOLOGY
F AILOVER
S PECIAL H ARDWARE
R EQUIRED
HA S COPE
Clustering
Automatic/Manual
Yes
Server
Database mirroring
Automatic/Manual
No
Database
Log shipping
Manual
No
Database
Replication
Manual
No
Database
As shown in Table 10-1 some of the technologies support an automatic failover, which
implies a minimal delay during which the database is unavailable during a disaster. Others
require a manual intervention, which can involve substantial delays if administrators arent
readily available to complete the failover.
Only one technology requires special hardware: a clustering solution. More details are given in
the section on clustering regarding the implications of choosing this technology. This requirement can substantially affect your ability to choose this technology for budgetary reasons.
The last column in Table 10-1 shows the scope of each technology as related to its HA
capabilities. Clustering operates at the server level, which means that all databases, logins,
jobs, and so on are covered in the HA solution and will failover to the secondary server.
Notification Services and Reporting Services can be configured to run under a clustered
solution and failover along with SQL Server in the event of a disaster.
The other three technologies are designed to operate at the database level, which means that
server-level items, jobs, logins, endpoints, and so on must be synchronized on the secondary
server and then enabled on that server manually if appropriate. These technologies only
ensure that the database data itself is available in the event of a disaster.
TAKE NOTE
Some technologies, such as the Service Broker and Notification Services, are contained
completely within a database. These HA technologies dont failover automatically to the
secondary server. Manual intervention is required to ensure that these services continue to
function in the event of a disaster.
HA technologies can greatly assist you in providing a stable data environment to your applications and clients, but they arent without limitations. Those limitations, along with some
misconceptions, are discussed in the next section.
214 | Lesson 10
The primary goal of any HA database system is to ensure that the database is always available,
any time of day or night, no matter what happens to any particular server. Although this is
the goal, there will always be a minimal amount of downtime as services move from the primary server to the secondary server. This can range from seconds to minutes in an automatic
failover to (potentially) hours for manual failovers. In choosing an HA technology and justifying the choice to management, you should explicitly state the downtime potentials even if the
technologies function exactly as designed.
Data-loss prevention is a goal of any HA solution in addition to ensuring access to the data. This
is usually accomplished by keeping the server accessible, and also by preventing hardware or software failures from causing any information stored in your database to be lost. The various technologies do this to varying degrees, some allowing no loss at all and others allowing you to specify
how much data youre willing to lose. This is expressed in terms of time, because the synchronization of data from the primary to the secondary servers takes place at a user-determined interval.
The administrator usually balances this goal of preventing data loss against the performance
or monetary costs of configuring a particular HA solution. This is often a difficult point
to explain to a nontechnical person, particularly a person in a management position.
Management never wants to hear that data could be lost and assumes that high availability
guarantees no data will be lost. An HA solution can be configured this way, but implementing
an HA solution isnt an absolute guarantee that no data will be lost.
An HA solution provides for database services to be available on one of two or more machines
in the event of a disaster. It does not, however, provide additional performance potential or
load balancing across the multiple machines. In most cases, the secondary server machine isnt
providing any database services for the application being protected by the HA solution. The
machine could be performing other functions, including supporting other SQL Server 2005
instances or databases, but it isnt providing additional performance to the database or application covered by the HA solution.
There are a few exceptions with database mirroring and log shipping, but the possible performance gains may not continue in a failover situation.
TAKE NOTE
Often, nontechnical individuals think that a cluster of two machines implies that half of
the requests are serviced from each machine, thereby providing a performance gain. HA
solutions are strictly for availability increases, not performance increases for your databases.
In addition to not providing additional performance for the application, the HA solution
doesnt load-balance clients for the database services. At any particular time, one or more of
the secondary servers has resources that arent being used and that are available for use only in
the event of a disaster.
Understanding Clustering
THE BOTTOM LINE
Clustering is a technology that uses the Windows Cluster Services to provide multiple server
nodes each providing SQL Server services using a central shared database on shared disk
drives typically setup in a SAN.
Clustering technology is based on Microsoft Cluster Services (MSCS) and has been available
since Windows NT 4.0 and SQL Server 6.5. This is often the first choice for administrators
who desire a highly available database server.
As shown earlier in Table 10-1, clustering operates at the SQL Server instance level, meaning
that all the instance services are protected from a hardware failure. In the event of a disaster,
all databases, logins, jobs, and other server-level services move to the secondary server.
A failover cluster works by having various resourcesin this case, including SQL Server
installed on the clusters nodes. A node is any Windows server participating in the cluster. At
any given time, only one node can own a particular resource and use it to provide services to
clients. In the event of a disaster, the service fails over to another node that activates its copy
of that service and begins responding to clients.
Clustering in SQL Server 2005 has been expanded from SQL Server 2000. SQL Server
Agent, Analysis Services, Notification Services, and replication are included in failover clusters
with SQL Server 2005; SQL Server 2000 only included failover of the database services.
Disk resources are shared among all nodes, eliminating the need to keep a separate copy of
any data for the resource synchronized on multiple nodes.
Abstraction for the client is provided by presenting a virtual instance of the servicein this
case, a SQL Server 2005 serviceto clients. Clients connect to this virtual instance rather
than to the actual instance running on the Windows server node. When the failover occurs,
this virtual instance moves to the secondary node, but its presentation on the network
remains the same so clients dont need to be reconfigured.
Clustering is also the most complex technology of those presented in Table 10-1. Clustering
imposes additional demands on the database administrator and equipment to provide this
level of HA capability.
WSC-certified hardware. The hardware used for your cluster solution must be on the
Windows Server Catalog (WSC) as a cluster-certified system. Each server node is the same
type and size of system. Its important to choose hardware from the cluster section, because
not all WSC resources are certified for clusters. If your solution will include a Storage Area
Network (SAN) device, then make sure the total solution is included on the WSC.
Shared disk resources. A special shared disk subsystem must be set up to allow all cluster
nodes to connect to the same physical disks. This usually requires specialty hardware.
Geographic limitations. Because a shared disk subsystem is involved, there are limitations as to how far the clustered nodes can be from each other. This is due to the
requirements for low network and disk latency. Although this distance increases as network speeds increase, the limit can prevent your solution from continuing to function
in some disasters.
Additional network configuration. A cluster requires a network link between the
nodesrecommended to be a private network linkthat allows the nodes to exchange
a heartbeat. This lets each node ensure the others are still functioning. Additional hardware may be required on each node.
Additional costs. In addition to ensuring that the cluster hardware is on the WSC,
often you must purchase additional resources, memory, disks, CPUs, or whole servers to
provide HA capabilities with a cluster solution. This can substantially increase the cost
of implementing this HA technology over other choices.
Software licensing is also a consideration, because all nodes participating in the cluster must
have the same version of SQL Server and hardware. This can add substantially to the cost of
the solution if you must license per processor, especially if you use an active/active solution
(defined in the next section). At the time of this writing, passive nodes dont require their own
SQL Server 2005 license.
216 | Lesson 10
The first part of your design involves determining the type of cluster scenario to implement.
With SQL Server, you must make two intertwined decisions. The first is the number of nodes
that will be a part of your cluster. SQL Server is limited by the underlying MSCS cluster and
OS limitations as well as SQL Server itself. With Windows Server 2003 or 2008 Datacenter
edition and SQL Server 2005 or 2008 Enterprise edition, eight node clusters or sixteen node
clusters, respectively, are possible. This means up to eight (or sixteen) Windows nodes can
be connected in a cluster, but because each Windows node can have multiple SQL Server
instances, you can actually cluster more than eight SQL Server instances. There are issues
with resource requirements, so in a practical configuration, its unlikely youd have more than
eight virtual SQL Server nodes present.
The standard edition of SQL Server 2005 or 2008 is limited to two nodes, and the
Workgroup edition doesnt support failover clustering. Windows 2000 supports only two
nodes unless you use the Datacenter edition, in which case four nodes are supported.
Related to the number of nodes is the configuration of each node. Any individual node can
be set to be an active node, meaning that its the primary server for a virtual SQL Server and
responds to client requests, or a passive node, meaning that its SQL Server service isnt actively
responding to requests and is awaiting failover from another node. These configurations are
referred to as active/active clusters or active/passive clusters.
This can be confusing, so consider a few examples. The simplest cluster is an active/passive
two-node cluster. In this configuration, shown in Figure 10-1, SQLProd01 is the primary
server and responds to client requests sent to SQLProd, the virtual instance. SQLProd02 is
the passive node, running idly and not responding to any client requests.
Figure 10-1
Two-node active/passive cluster
Client
SQLProd
SQLProd01
SQLProd02
Shared Disk
If SQLProd01 fails for some reason, SQLProd02 will become the primary server after failover
and start responding to client requests. Only one servers resources are used at a time, meaning that half your server hardware (excluding disk drives) isnt being used at any given time.
In this case, only one SQL Server license is needed for the one virtual server.
A second example, illustrated in Figure 10-2, shows a three-node, active/active cluster with three
physical servers and three virtual servers. In this case, each server is actively used at all times to
do work, and three SQL Server licenses are required for the three active server instances.
The failover strategy is more complex in this example, with each server having a designated
failover server in a round-robin fashion. Table 10-2 shows the virtual servers, primary physical
instance, and the failover physical instance.
Figure 10-2
Three-node active/active
clustering
Client
SQLProdA
SQLProd01
SQLProd02
Shared Disk
SQLProdC
SQLProdB
Client
Client
SQLProd03
Table 10-2
Three-node failover
V IRTUAL S ERVER
P RIMARY S ERVER
S ECONDARY S ERVER
SQLProdA
SQLProd01
SQLProd02
SQLProdB
SQLProd02
SQLProd03
SQLProdC
SQLProd03
SQLProd01
If any node fails, then the virtual server moves to another instance. However, when this
occurs, one physical server will be spreading its resources to serve two virtual instances. In
this example, if SQLProd02 fails, then SQLProd03 must serve clients connecting to both
SQLProdC and SQLProdB.
In order for the applications to function at a similar performance level, each server must have
enough spare processor cycles and memory to handle the additional load of a second instance
in the event of a failover.
218 | Lesson 10
The last example, shown in Figure 10-3, has a four-node cluster with three virtual nodes. In
this configuration, the cluster is set up in an N 1 configuration with three active nodes. One
passive node acts as the failover node for any of the three active nodes. This type of cluster
requires three licenses for software; in addition, the passive node must have enough hardware
resources to handle the load for any one of the other three nodes.
Figure 10-3
Four-node cluster in an N 1
configuration
Client
SQLProdA
SQLProd01
SQLProd02
Shared Disk
SQLProdC
Client
SQLProdB
SQLProd03
SQLProd04
Client
In all of these examples, the cluster solution should be designed with a specific performance
goal in mind. Because the secondary node in any of these cluster examples will receive an
increased load in the event of a failover, its hardware should be designed to handle the desired
level of performance. If the same level of performance is desired, as it often is, the secondary
server should have the same hardware configuration as the primary.
If the cluster is in an active/active configuration, then each server should have enough hardware to handle its own load as well as the additional load from the node that would fail to
it. When the same performance is expected from the secondary server, a level of hardware
equivalent to that on the primary server will sit idle until a disaster event occurs. This idle
hardware is essentially an insurance cost that must be weighed against the cost of downtime
if the SQL Server instance fails.
Clustering Enhancements
SQL Server 2008 includes a set of enhancements for improved clustering. These
enhancements generally rely on enhancements included with Windows Server 2008. The
SQL Server enhancements include the following features:
Cluster Validation Tool. This is a tool provided with Windows Server 2008. SQL Server
2008 requires a successful result from this tool in order for clustering to proceed.
When designing your cluster hardware, keep in mind that you need to design for the performance goal of each node when another node has failed. This usually means that the hardware
chosen for processor and memory needs should be able to handle the load of the primary and
secondary virtual servers that may potentially be running together.
For example, looking again at the three-node cluster example shown previously in Figure 10-2,
assume that each virtual SQL Server instance requires two CPUs and 4 GB of RAM to
meet its performance goals. The failover design requires that each node have four CPUs and
8 GB of RAM. If SQLProd01 fails, then SQLProd02 will be running both SQLProdA and
SQLProdB. To meet the performance goals, four CPUs must be dedicated to each instance,
for a total of eight CPUs. The RAM must be similarly configured.
Because your servers may not have equal CPU and memory requirements between the
multiple applications, you should add the needs of the instances that will run together and
purchase the amount of resources required for that node.
220 | Lesson 10
TAKE NOTE
If your requirements dictate an odd number of processors or memory that doesnt fit into
your hardware choices, its better to round both up to the next number of processors or
RAM. If you determine that a server needs three CPUs to meet performance goals, purchase four CPUs rather than two. This will be a minor additional expense and some hardware choices may require an even number of processors anyway.
Your hardware design also needs to specify how the hardware will be configured with the
different instances that are running. If you have a passive node that will support only one
instance in a failover situation, then you can dedicate all the resources to this instance.
However, if youre running active/active clusters, you should specifically dedicate an amount
of memory to each instance. Doing so prevents problems when the second instance starts up
during a failover event and the two instances compete for RAM. You should also set an affinity
for CPUs between the instances to ensure that enough processor resources are set aside in case
of a failover event.
CERTIFICATION READY?
Understand how
clustering differs from
other technologies
such as mirroring or
replication.
The last part of designing a clustered solution is being aware that the versions of Windows
and SQL Server must be the same on all nodes. You cant mix editions or 32-bit and 64bit versions in a cluster. This can have implications for the combinations of different SQL
Servers onto a clustered solution. If you have applications that only require 32-bit SQL
Server 2005 Standard Edition and others that require 64-bit Enterprise Edition, then
combining them on a cluster may mean spending more money on hardware and licensing
for the Standard Edition applications than is justifiable. You should perform a careful ROI
analysis when combining different applications to be sure the cost is worth the benefits.
Database mirroring is a technology in SQL Server that uses two copies of the database
and provides for automatic failover in the event that one database experiences a disaster
event.
Database mirroring technology was designed to provide a very high level of database availability using lower-cost hardware than clustering. There are a number of differences between
clustering and database mirroring, and the best choice for your environment depends on the
particular needs of your organization.
TAKE NOTE
Failover delay. Clusters fail over in 30 seconds to a few minutes, depending on the time
required to start the secondary instance and fail over the resources. Database mirroring can fail to the mirror database in a few seconds. Both technologies allow manual or
automatic failover.
Scope. Clustering operates at the server level, including SQL Server Agent, Notification
Services, other services, and all databases. Database mirroring only works at the database
level and requires that logins and any server-level resources that are required be synchronized across both servers.
TAKE NOTE
From this list, it may appear that database mirroring addresses most of the shortcomings of
clustering, fails over more quickly, and should be used everywhere clustering was previously
used. Although database mirroring does provide many benefits, it isnt always the best choice.
The limited scope of database mirroring to a single database means that more administrative
work is required to ensure that the application will continue to function correctly in the event
of a failover.
Database mirroring is a robust technology that is usually easier to set up and administer
than clustering, at a much lower cost. With its ability to provide for limited reporting using
database snapshots, fast failover times, and zero-data-loss protection, its a great alternative for
many organizations user databases.
This technology works by applying all log recordsessentially, every change that occurs
from a principal database to a secondary database. The exact timing of this application
depends to some extent on how the database mirroring is configured. The application ensures
that all changes made to the principal database are reflected on the mirrored copy.
The next section will examine the configuration of a database-mirroring environment.
222 | Lesson 10
This mode is most appropriate for situations requiring automatic failover and zero data loss.
In conjunction with new ADO.NET 2.0 or SQL Native Client features, clients can automatically redirect to the mirror server when a failover occurs.
TAKE NOTE
Because database mirroring operates at the database level, you must set up a separate mirroring session for each database on an instance that you wish to protect. These separate
databases dont all have to mirror to the same mirror server. You can use different physical
servers for each mirror database.
Your client applications, however, may dictate the feasibility of using database mirroring.
If youre using Open Database Connectivity (ODBC), Object Linking and Embedding
Database (OLEDB), or an older database connectivity technology, then youll need to code
custom connection logic or set up some sort of load-balancing solution to allow clients to
redirect to the principal server. Using a load-balancing appliance and DNS names for connectivity can seamlessly allow clients to connect to the proper server automatically.
If you dont have this type of solution, you may have to manually alter the connection strings
for your client application in the event of a failover. Although the database may be available almost instantly after a failover, your clients wont realize this until their application can
reconnect. The ability to redirect to the failover server is critical in designing your databasemirroring environment.
If youre using the SQL Native Client or ADO.NET 2.0 technologies, the connection strings
for connectivity can contain a primary and mirror server. This lets the client seamlessly find
the appropriate server.
In designing the mirror solution for your environment, make sure to account for the fact that
mirroring protects at a database level, not a server level. This means that as you add logins,
they should be added manually on the mirror database as well. Any server-level jobs that you
have running must be set up on the mirror database as well.
One last consideration is that the mirror database isnt accessible or available to clients. It sits
idle, accepting transactions until it switches roles and becomes the principal in a disaster. One
way around this is to configure a snapshot based on the mirror database. Doing so gives you
a point-in-time view of the data. However, this snapshot must be continually dropped and
rebuilt to see the data changes occurring in the mirror database.
224 | Lesson 10
TAKE NOTE
TAKE NOTE
LAB EXERCISE
The first step in enabling database mirroring is to ensure that the security for the database
mirroring session is set up. You have the choice to use either Windows authentication or certificates for the log-record transfer. This choice depends on your situation. If the servers are in
the same domain or in a trusted domain, then you can use Windows authentication. If youre
coming from an untrusted domain, you can use certificate authentication. In either case, a
login must be set up on the mirror server to allow the transfers.
The log-record transfers take place through the use of a special endpoint called a databasemirroring endpoint. This endpoint must be established on each server, principal, and mirror, and
the network configured to allow traffic on the specific port chosen for communications. Because
multiple databases can be mirrored from a single instance, you should specify a different port for
each database. These endpoints are created using the CREATE ENDPOINT command.
Once you have the communication channel set up, you must initialize the mirror database.
You do so by taking a full backup on the principal server and restoring it on the mirror server
using the same database name as the principal. All log backups taken since the full backup on
the principal must also be restored on the mirror server. This ensures that a full copy of the
principal databases data is on the mirror database.
At this point, both servers are configured for mirroring, and the session can be enabled.
Starting with the mirror server and then on the principal server, run the ALTER DATABASE
command with the SET PARTNER option to specify the opposite server and designated
TCP port for mirroring. Doing so enables database mirroring and begins the transfer of log
records from the principal to the mirror.
In Exercise 10.1, youll set up mirroring on the AdventureWorks database. This exercise
assumes that the database server was installed as the first named instance on the C: drive. If
youve installed your server in a different place, modify the paths to match your system. Be
sure the recovery model for your AdventureWorks database is set to full. In addition, a second
instance of SQL Server 2005 is required. It can be on the same server or a different server.
This exercise has SSC10\SS2K5 as the primary instance and SSC10\Sales as the secondary
instance. Again, adjust for your circumstances.
You should test for two types of failover events: planned failovers, such as for maintenance
activities; and unplanned failovers, which are any failovers that havent been scheduled and
communicated to the appropriate people.
For planned failoverstypically, maintenance activities such as hardware or software
upgradesyou can develop a testing strategy using the manual failover commands. This
entails running the ALTER DATABASE command with the SET PARTNER FAILOVER
option on the mirror server, which forces a failover from the principal database to the mirror
database. Because this command will be run during a planned failover, you can ensure that all
clients connect to the mirror server, that all data changes have been synchronized on the mirror database, and that all logins are available. Your testing strategy should ensure that a new
TAKE NOTE
login is added on the primary as well as some particular piece of data changed prior to the
failover. If your configuration and procedures are correctly set up, youll be able to test that
those changes have been copied to the mirror server.
Unplanned events are slightly harder to test, but they can still be simulated. As with planned
events, you should explicitly create marked data, logins, and possibly other server-level items
on the principal. You can simulate an unplanned failover by pulling the network cable out of
the principal server. Doing so simulates a hardware or software abend (abnormal end) on the
principal server as well as a network failure, any of which could cause the failover.
If your servers are configured for automatic failover, you can check whether the marked data, logins, or other specific events have been copied to the mirror server correctly. Because some of these
objects require manual synchronization by a database administrator, you should have procedures
in place to handle the case where the objects havent yet been moved to the mirror server.
TAKE NOTE
Because the principal database may not be available in a real disaster situation, you cant
refer to that SQL Server instance for the details of the object. You should make a paper
record or offline notation of the objects as part of the procedure for creating them on the
principal database.
In either of these test cases, make sure you test connectivity to the mirror database from all
the locations that require connectivity. This is especially important if you have geographically
dispersed mirrored servers. Your SQL Servers may failover quickly, but if clients cant access
the remote SQL Server, then the application wont be seen as available.
Mirroring Enhancements
SQL Server 2008 includes a series of changes designed to improve mirroring performance. Prior to SQL Server 2008, mirroring was a one-way activity in that the principal
server sent data to the mirror server. Now with SQL Server 2008 and the feature for
automatic page repair each server can attempt to recover page data from the other server
participating in the mirror. If page repair is successful, all of the data is preserved. This
is because the second server in the mirror should have a perfectly good copy of the data
with which to perform the repair. In contrast, correcting errors by using the DBCC
REPAIR_ALLOW_DATA_LOSS option might require that some pages, and therefore
data, be deleted. Note however that if a corrupted page has been caused by some form of
drive hardware failure, recovery may not be possible and immediate attention should be
given to the situation.
CERTIFICATION READY?
Be prepared to answer
questions involving
a witness server.
Is a witness server
required for automatic
failover? What are the
hardware and software
requirements for a
witness server?
Compression of mirroring data. The log data being transmitted from server to server
is now compressed. The result should be less latency between a change on the primary
server and the corresponding change on the mirror server.
Write-ahead log. Writing log data to disk before all data has arrived on the mirror server
also improves the speed of completing transactions.
Improved efficiency of log send buffers. SQL Server 2005 reserves an entire log send
buffer for any log flush operation. SQL Server 2008 now appends log records to the current buffer if enough space is available.
Read-ahead during undo. During a planned mirror failover, the new mirror server (the
former principal server) must undo all transactions that are not completed on the new
principal server (the former mirror server). Page read-ahead improves the efficiency of
this operation.
226 | Lesson 10
CERTIFICATION READY?
Logs are usually moved
to the standby server on
a scheduleperhaps
every 15 minutes. If the
file transfer takes 20
minutes to complete, log
shipping may not be a
suitable option. Watch
for these details in the
certification tests lengthy
scenario.
Log shipping is a technology for high availability that is based on the normal log-file backup
and restore procedures that exist with SQL Server.
In a log-shipping environment, transaction-log backups are made on the primary server and
then copied to the secondary server, where theyre restored. Prior to SQL Server 2005, the
Enterprise edition of SQL Server was required for this process to be automated, but many
people developed their own scripts to simulate log shipping with the Standard edition.
In the event of a disaster situation, the final transaction logs are restored on the secondary
server, and then the status of that server is changed from a loading database to an active one.
These final steps must be performed manually or with custom scripts. SQL Server provides
no automatic way to do this.
Because log shipping uses regular file-transfer methods between servers, the log backups can
be copied to multiple servers, allowing multiple servers to be used for redundancy. This is an
advantage over clustering or database mirroring, although you can combine database mirroring with clustering to copy the log records to other servers from the mirror server.
Log shipping also has another advantage over database mirroring and clustering: You can use
the secondary database for reporting and other read-only queries. If the secondary is a separate server, then the HA resources are put to use instead of standing by idly.
The disadvantage of using log shipping is that the application and server roles dont fail over
automatically. An administrator must manually bring the secondary database online, and you
must develop a method for ensuring that the application will use the secondary server. Because
manual intervention is required, the delay between when a disaster event occurs and when the
secondary server comes online will be greater than either clustering or database mirroring.
Another issue with this technology and failover is that the names of the servers on the network must be different to comply with the Windows networking requirements. You must
develop a method to ensure that the clients can find and connect to the secondary server.
As with database mirroring, this is a database-level protection mechanism. Any server-level
logins, jobs, or other objects must be manually kept in synchronization by an administrator
on both servers.
TAKE NOTE
A log-shipping configuration includes three possible roles: the principal server, the secondary
server, and the monitor server. As with the other technologies, the primary server is the
production server that clients normally connect to for queries. The secondary server is
the server to which the database fails over if a disaster event occurs. The monitor server,
which is optional, should be a separate server that stores tracking information about the
backups and restores.
Similar to database mirroring, the hardware required is the regular hardware required for SQL
Server. The principal and secondary servers dont need to be the same or even similar hardware.
Similar to clustering, you can have multiple principal databases, from separate instances, all
configured to fail over to a single SQL Server instance. This is a similar configuration to the
N+1 configuration used in clustering. This is a common configuration; because its unlikely
that more than one principal server will fail at the same time, so resources are conserved in
this situation.
The processor and RAM requirements for your secondary servers should be based on the
performance goals that must be met and baselines from your existing servers.
CERTIFICATION READY?
Remember that log
shipping requires manual
intervention in order to
switch roles between
servers.
228 | Lesson 10
The first of these is the most straightforward. In the connection string used by the clients,
whether this is ADO.NET, ActiveX Data Objects (ADO), OLEDB, or another mechanism,
change the name of the server to that of the secondary server. Depending on how centralized your connection strings storage is, this may or may not work well. If youre supporting a
single web server with the connection string stored in a global variable, this is easy to deploy
because only one file is changed. Similarly, if your clients read the connection string from a
central location, then you can easily deploy this to a large number of clients. If the string is
coded into the registry on every client machine, this may not be the best choice for your environment. Your decision to use this method will largely depend on how your application and
its connection strategy are architected.
The second choice is also fairly straightforward, but its a little more tedious. In this scenario,
you rename the Windows host of the secondary server to the name of the primary server.
Doing so requires that the primary server has already been renamed to something else or that
its offline. You may or may not elect to also change the network addressing, but that again
depends on your application. You must also rename the SQL Server 2005 instance to match
the Windows host, to ensure that clients can reconnect.
As an example, if your primary server is named SQLProd01 and your secondary server is
named SQLProd02, you take the primary (SQLProd01) offline or rename it to SQLProd03
(or some other unique name). Then, rename the secondary (SQLProd02) to SQLProd01
and also rename the secondary SQL Server instance on SQLProd02 to SQLProd01. If the
old primary is repaired and ready to come back online, you need to rename the secondary
(the original SQLProd02) back to SQLProd02 or another name before bringing the original
SQLProd01 back on the network with that name. Note that renaming also involves name
changes in any Active Directory domain as well as the name entries in your DNS server.
This is confusing, and if the failover isnt permanent, you may not wish to choose this strategy.
Depending on the network configuration of your Active Directory domain controllers and
DNS servers as well as the lifetimes of cached DNS client entries, there may be a substantial
delay while the clients update their cached name lookup entries and the naming converges
onto the IP address of the renamed secondary server.
The final method is preferred by most companies and involves using your network
infrastructure to abstract the SQL Server address from the actual machine. You can
choose to use DNS or a load-balancing scheme to route traffic at the network level to the
appropriate server. For example, if you have all clients connect to a hostname in DNS such as
sql.sqlservercentral.com, instead of SQLProd01, then if SQLProd01 fails, you can change the
DNS entry for sql.sqlservercentral.com to resolve to SQLProd02.
This way, none of the clients must change, and the Windows names used by the clients
remain the same. The convergence of the name to the new address may still take some time as
clients flush their DNS caches.
A load-balancing device, either hardware or software, can be even simpler to use. If you have
all clients address the load-balancing device, it can instantly direct clients to the new server.
This is the preferred method if your network infrastructure supports it.
Understanding Replication
THE BOTTOM LINE
Replication is a term for multiple different types of processes that copy transaction data from
one or more database servers to one or more other servers.
The replication technology available in SQL Server isnt specifically developed for high availability. Instead, replication is designed to enable data to be moved from one or more servers
to another in a publisher-subscriber model. It can be adapted for high availability because it
automates the movement of data to remote servers.
Three types of replication are available in SQL Server: snapshot replication, transactional replication, and merge replication. Because snapshot replication operates on the entire set of data
at one time, this type of replication isnt suitable for an HA solution.
Transactional or merge replication, however, can operate at the transaction level. As quickly as
the transactions can be copied to the distributor and sent to the subscriber, theyre executed on
the secondary server, making both of these solutions good for implementing an HA solution.
230 | Lesson 10
NodeA. Twenty seconds later, NodeAs value is overwritten by the replicated value from
NodeB. In this case, youll have different data on each system.
If youre allowing this to occur on your systems, and theyre intended to be used for high
availability, you should ensure that code checks are run on a regular basis to look for this
disparate data. The way in which you deal with the data will be specific to your business
requirements. You must decide how the potential issues with data-update conflicts can be
handled. Youll need to perform manual updates to the nodes with the incorrect data based
on what you decide for your business.
In merge replication, you can specify whether the first update, the last update, or custom resolution code is used to determine which value is written to all nodes. In any case,
where data can be updated on multiple nodes, you specify how conflicts will be resolved.
However, as with bidirectional transactional replication, the business rules for deciding
how conflicts are resolved will be specific to your business requirements.
Unlike the other HA technologies, merge replication lets you split client connections among both
nodes. A load-balancing technology used to direct clients to both nodes can immediately send
clients to the surviving node in the event that the other node fails. This can provide a seamless
transaction between nodes in addition to balancing the load across multiple nodes for scalability.
If you choose to share the load with multiple servers, make sure youre aware of the performance
reduction that will occur if one node fails. If a reduced performance capability is acceptable in
the event of a disaster, then this can be a good technology for a highly available system.
TAKE NOTE
Server 2005, requires even more protection, because only one set of disks is shared between
the nodes on which the data is stored. The other three technologies have separate disk subsystems for the primary and secondary nodes, providing some degree of fault tolerance.
In designing a highly available storage solution, the method used for disk drives is the
Redundant Array of Inexpensive Disks (RAID). This technology is available in many forms
and possible combinations, each of which has different advantages and disadvantages.
Storage Area Network (SAN) technology is another way of building on the benefits of
RAID arrays to provide even more fault tolerance and better performance. Both of these are
discussed next.
232 | Lesson 10
RAID 5 provides a good balance between the cost of multiple disks and the performance
of RAID 1 for reads. Unless you need to build a very high level of performance into
your database files, this is a great choice for most database data files.
RAID 10. Also known as RAID 1+0 because it combines the RAID 1 and RAID 0 levels to get the benefits of both. This is one of the highest-performing RAID levels, but its
also one of the most expensive options. A minimum of four disks is required to implement RAID 10.
RAID 10 is the best choice in SQL Server instances where high performance is required
and the expense of this level can be justified.
LAB EXERCISE
CERTIFICATION READY?
RAID is a technology for
providing redundancy
at the drive level. Watch
for exam questions that
discuss HA requirements
that are focused beyond
disk drives.
However you choose to design your arrays, have extra disks available in case of failures, preferably operating in standby mode if your RAID controller supports hot spares. You also need to
choose how to separate your data files, as discussed in Lesson 3.
In Exercise 10.2, youll walk through designing a series of RAID arrays for a SQL Server
instance. In this exercise, youll examine building a series of RAID arrays for an instance of
SQL Server. The decision has been made to build one 16 GB array for the OS and pagefiles,
one 70 GB array for the log files, one 500 GB array for the data files, and one 50 GB array
for the tempdb database. You have 35 GB and 70 GB drives available for the arrays.
TAKE NOTE
SANs utilize a complex technology and require specialized training to set up and manage.
In many large organizations, a single person is often dedicated to managing the equipment.
A complete discussion of SAN technology is beyond the scope of this text; however, a DBA
should be aware of some basic principles and ensure that they are implemented if the DBA
will be managing SQL Server instances whose data is stored on a SAN device.
CERTIFICATION READY?
Remember that a SAN
is still a single storage
mechanism. Highavailability requirements
may necessitate storage
of data at multiple
physical locations.
Some SAN implementations have captive disks inside the Windows host that are used to boot
the operating system leaving the SAN disks for data storage. Others boot the Windows server
directly from the SAN disks. If your database server uses the former design, make sure those
captive disks are protected by RAID. If they fail, the Windows operating system will fail even
though the SQL Server data will be protected and available on the SAN.
The last part of designing a fault-tolerant SAN solution is ensuring that the SAN device has a
backup solution designed into it. Because SAN devices often implement multiple terabytes of
data, its crucial that this data, or at least your SQL Server data, is protected. You should use
either a second SANpreferably, geographically remote from the primary SANand/or a
tape backup solution to ensure that the data is available in the event the SAN device fails.
234 | Lesson 10
The failover time is one of the main factors that influences the type of solution youll implement. A failover time measured in hours means that you can choose almost any solution,
including building a server from scratch in a motel. However, a failover time in minutes or
seconds may mean that youre limited to clustering or mirroring. Because log shipping or replication requires manual intervention, the time required for an administrator to respond will
determine if you can use these technologies.
TAKE NOTE
If you require an administrator to respond to a disaster situation, make sure you test the
response time and enact rules to guarantee the response times can be met. For example,
you may want to ensure that the on-call administrator is never more than 30 minutes from
a computer.
Closely related to the failover time is whether automatic failover is required. If so, then youre
limited to clustering or mirroring unless you have and can spare programming resources to
build an automated solution.
Application issues also play a part in the HA solution you can build. Server instancelevel
protection often mandates failover clustering, although you can conceivably use database mirroring, log shipping, or replication on all databases that need protecting. If you require SQL
Server Agent, Notification Services, or Reporting Services to be fault tolerant, then you may
be limited to clustering unless you can build creative solutions that can handle your needs.
The applications ability to handle disasters also will influence your choice of technology. If an
application cant be modified to work with server-name changes or other addressing considerations of some technologies, clustering or database mirroring may be your only choice for a
solution.
Finally, you should weigh the cost of the technology against the benefits of the HA solution.
An application that will cost you $100 per hour of downtime may not justify the cost of a
$50,000 cluster. Each solution you design will potentially have additional hardware costs,
vendor support costs, licensing costs, employee costs for on-call or after-hour on-site support,
and more. The total cost for each solution should take all these items into account. The cost
of downtime and the risk of downtime occurring should be compared to the solution cost to
determine if the solution is worth implementing.
No matter which type of technology you choose, the SQL Server hardware should be built
with fault tolerance in mind. This usually means spare parts for the various components of
the database server, but it could also include RAID technology, spare network paths, and vendor SLAs to ensure that your SQL Server instance will continue to function in the event of a
disaster.
The main thrust of an HA plan is to limit the single points of failure as much as possible.
All the technologies discussed earlier are aimed at preventing a single database, server, or disk
from being a single point of failure. There are a few other items to consider in designing your
solution, discussed next.
Recognizing that your staff is critical to the successful continuation of operations in the event
of a disaster involves two phases. First, you need to ensure that processes and procedures are
documented and employees are cross-trained. Doing so helps prevent any one person from
being a single point of failure.
TAKE NOTE
Its often hard to ensure that technical employees dont make themselves a single point of
failure. Sometimes theyre averse to documenting too much of their job for fear of working
themselves out of a position. Show your employees that theyre valuable in spite of the fact
that you have someone else who can perform their job.
The second part of mitigating staffing issues is planning for the problems people may experience and helping them work through those issues. Rotating shifts, providing help for families,
or other means of ensuring that your staff is able and willing to help the company through a
disaster situation can mean the difference between your database continuing to function or
never coming online again.
HA T ECHNOLOGY
Failover clustering
Database mirroring
Log shipping
Replication
Your choice for a reporting solution should take advantage of the potentials of each technology
for meeting this need. However, it should be a secondary criteria for choosing a solution
meeting your HA needs should be the primary objective.
TAKE NOTE
You can combine the HA technologies to achieve your needs, especially for reporting. Log
shipping or replication can be combined with database mirroring or clustering to build a
reporting server.
236 | Lesson 10
The last part of building an HA system is moving your current environment to a highly
available one. This section assumes that you have a system running that isnt fault tolerant,
and you wish to move the system to an environment that is designed to function in the event
of a disaster.
Because the system you design can be as simple or complex as your resources allow, its impossible to discuss all possibilities, but some general guidelines can help you ensure a smooth
transition to the new environment.
However you choose to perform the migration, its critical that you test the plan. Your HA
solution will probably be with new servers, so set up a development or spare server as close as
possible to the existing SQL Server database server and test the steps for moving the database,
jobs, logins, and so on. Ideally, you should capture a real-world load using Profiler on the
production server and replay that during the migration test to be sure the workload can be
executed.
There may be a few or hundreds of steps to perform the migration, and you should document the order in which they occur as well as who should perform them. Doing so will help
ensure that the process proceeds smoothly.
Finally, you should test the failover and failback after the migration. Failback is the reverse of
failover in that failback refers to transferring the role of the principal server or database back to
the original server or database. Moving to an HA system makes sense only if youre sure that
the failover in the event of a disaster, and the failback later, can be performed when needed.
Minimizing Downtime
Depending on which technology you choose and the structure of your current environment, its possible to eliminate any downtime for the application. If youre adding to your
existing environment, such as implementing log shipping, mirroring, or replication on
an existing SQL Server instance, you can add these items to your database and initialize
them without interrupting your applications access to the database.
Even if youre choosing to move to new hardware with one of these technologies, you could
conceivably add the technology as youre moving from the old server to the new one and then
fail over to the new server. This should be done only after some testing of the solution, but
it can move you onto a new server transparently to the application. You can then reconfigure
the old server or even replace it with another server and reconfigure the failover.
If youre implementing a cluster from a previously unclustered solution, youll require downtime to move the data and bring it up on the cluster. On a SAN, this process can be as simple
as presenting the same disks to the new server, thereby minimizing downtime. If not, then
you should perform extensive testing and documentation of the process for migrating the
application to ensure that the actual migration occurs as smoothly as possible.
S K I L L S U M M A RY
A highly available system is unique for many companies, involving those technologies and
processes that guarantee the system functions at the necessary level for the enterprise. The
scale and capabilities of the secondary system that is used if the primary system is unavailable
depend on the requirements of your organization.
Each of the four technologies available in SQL Server to implement highly available database
servers has its own features, disadvantages, and costs. The technology that is appropriate for
your application depends on the businesss needs for that application. No single technology is
right for all applications.
238 | Lesson 10
As you design high availability into your database servers, make sure you consider all
technologies equally in determining which one is best suited for your application. Examine the
entire system, from hardware to network to staff outside of the four technologies, to ensure
that the entire application has as few single points of failure as possible.
For the certification examination:
Understand the SQL Server failover clustering. You should know the capabilities and
limitations of failover clustering as an HA technology in SQL Server. Also know the
requirements of this technology over and above those of non-clustered SQL Server.
Understand SQL Server database mirroring. You should understand how database
mirroring works in SQL Server and when its appropriate to use as an HA technology.
Know when to use log shipping. You should understand where and when log shipping can
be used to build a highly available system.
Understand how replication can be used in an HA system. Know which types of replication
can be used to build an HA system as well as the limitations of choosing this technology.
Identify single points of failure. You should understand what a single point of failure is
and how to identify the single points of failure in your system.
Know how to migrate your application to an HA environment. You should understand how
to develop a migration plan for your application to move to an HA environment.
Knowledge Assessment
Case Study
Eds Heavy Equipment
Ed Harvey started an equipment-rental business in southeastern Virginia that specializes in home garden and tractor equipment. The company has equipment in a number
of home stores that customers can rent to use in their gardens, farms, or yards. Remote
terminals in each store communicate with a central office where the database server
tracks all rentals.
Planned Changes
The business has grown substantially, and now Ed wants to enable customers to reserve
equipment over the Internet as well as at stores. He wants to be sure his business continues to function even if a disaster occurs at one store or the central office.
The IT staff wants to be sure they choose the best combination of technologies to build
an HA system while being careful of the overall cost of the system.
Existing Infrastructure
There is a single Active Directory domain to which all employees authenticate.
The current SQL Server 2005 server hardware is adequate, but a new server is expected
to be purchased this year to increase performance.
Each store has its own client machines, at least two per store, to connect to the central
office across a high-speed private network. Each store can also communicate with all
other stores via instant messaging, so clerks can send messages to each other.
Every store has room for its own server. The business considered this option initially,
but decided against it.
Business Requirements
Ed wants to be sure that if something happens to the server in the central office, all
clients can continue to connect to this server without interruption.
There is a remote possibility that the central office could go offline because of construction work in the area. Ed has arranged for another web server and separate connection
to the Internet at the Chesapeake store. This web server currently connects through the
private network to the central office. If the central office loses its Internet connection,
the Web site should continue to accept reservations. A delay of an hour or two to get
this running is acceptable.
Clients can be reconfigured to connect to another server if a long outage for the central
office is expected, but this isnt acceptable for short-term problems.
Technical Requirements
The solution designed should take advantage of SQL Server 2005 HA technologies to
meet the business requirements.
A few new servers can be purchased, but separate servers cant be placed in every store.
The private network provides adequate connections between stores for all client traffic
in the event of a disaster at the central office. It cant support disk-access traffic.
The ISP for the company provides load balancing from the Internet for both web
servers using the two separate connections from the central office and the Chesapeake
store. However, the internal connection from the web servers to the database server
is managed by the internal IT staff. If the database services move to a new server, the
connections should transition easily to the new server.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions.
1. To ensure that the central office is adequately protected, new server hardware is being
purchased. Which technology would you choose to protect the database and ensure that
all SQL Server Agent jobs continue to run if the primary server has problems?
a. Failover clustering
b. Database mirroring
c. Log shipping
d. Replication
240 | Lesson 10
2. You decide to implement automatic failover from the central office for the application
in case that office goes offline. Which technology is best suited for this?
a. Failover clustering
b. Database mirroring
c. Log shipping
d. Replication
3. To ensure that all clients can redirect to a new server in the event of a disaster, how
should you set up the new servers?
a. Set the VIP to SQLRental01 on the cluster, and name the mirror server
SQLRental02.
b. Set up a DNS host as SQLProd, and direct it to the cluster. In the event of disaster, it
can be moved to the secondary server.
c. Change the application to try the primary cluster node Windows name first and then
the secondary cluster node Windows name.
d. This cannot be done with SQL Server 2005.
4. One of the senior managers wants to consider the possibility of having multiple failover
databases to ensure that two failures do not stop the business. Which technologies can
you use to meet this objective? (Choose all that apply.)
a. Failover clustering
b. Database mirroring
c. Log shipping
d. Replication
5. The application supports mostly OLTP traffic, with a good mix of reads and writes. Your
server has five drives in it, and you want to ensure that you protect the data as well as
have as much storage as possible. Which type of RAID should you choose?
a. RAID 0
b. RAID 1
c. RAID 5
d. RAID 10
6. Which of the following can you leave out of your HA design, given the fact that the
company has never used clustering?
a. SAN devices
b. Staff training on clustering
c. RAID technology
d. A secondary server
7. You are considering separating the store rentals from the Internet customer reservations
in two databases. To do this while ensuring that your system is still fault tolerant and
with minimal application changes, which technology should you choose?
a. Failover clustering
b. Database mirroring
c. Log shipping
d. Replication
8. You decide to implement database mirroring between two servers after upgrading all
clients to use the SQL Native Client that ships with SQL Server 2005. What do you
need to do to support automatic failover?
a. Build retry code into the application to try the primary server and then connect to
the secondary server.
b. Use two connection strings, one for each server, and have the application try both
each time it runs a query.
c. Add the secondary server into the connection string as the secondary databasemirroring server.
d. Put both servers behind a load-balancing device to handle this.
9. The application has been modified to have customer reservations connect to one server
and store reservations connect to a second server with merge replication moving data
between the servers. Customer orders from the Internet should take precedence over
store orders if the customer has an account. How can you ensure that this happens?
a. Set up the replication to always start with the Internet server and send data to the
store server.
b. Use custom code to resolve replication conflicts.
c. Set the priority of the Internet server lower than that of the store server.
d. Have the Internet application write to both servers.
10. As a secondary plan to your clustering solution, you decide to have log shipping send
copies of the transaction logs to the Chesapeake store. To enable managers to query
this database and not load the primary database, what option should you use with the
restores?
a. WITH STANDBY
b. WITH RECOVERY
c. WITH REPORTING
d. WITH ONLINE
11
Designing a Data
Recovery Solution
for a Database
LESSON
L E S S O N S K I L L M AT R I X
TECHNOLOGY
SKILL
EXAM
OBJECTIVE
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
business continuity plan (BCP):
A policy that defines how an
enterprise will maintain normal
day-to-day operations in the event
of business disruption or crisis.
decision tree: A technique for
determining the overall risk
associated with a series of related
risks; that is, its possible that
certain risks will only appear
as a result of actions taken in
managing other risks.
242
So far in this textbook youve learned several key aspects about designing your SQL Server
database infrastructure. These have included considerations of physical design, hardware
needs, security issues, and so on. But no matter how well you design, plan, anticipate, and
prepare, things inevitably go wrong, and disaster strikes. The permanent loss of data is a
catastrophic event that can cripple an organization.
Given those considerations, it isnt surprising to discover that one of the primary responsibilities of a database administrator is to secure the information contained in the user databases.
This responsibility consists of several tasks, including designing for fault tolerance, developing
a data restoration strategy that anticipates disaster, and securing the data.
Not having a reliable, carefully thought out disaster plan is an open invitation to catastrophe
and borders on inexcusable criminal negligence. Its as if you decided to jump out of an
airplane without a parachute, expecting the trees below to catch you. It might work, but
its not a viable plan. In this Lesson, youll examine how to plan a data recovery strategy for
databases, including a backup and restore plan.
Although youll primarily focus on best practices, you should make a habit of establishing and
applying general principles when planning and using data-recovery techniques across your
infrastructure rather than trying to design a different plan for each database. Establishing and
using general principles can save you both time and money.
For example, assume you decided to design an individualized data-recovery strategy for
each database in your system. Doing so would probably result in having procedures that
vary from server to server. The subsequent plan would be unnecessarily complex. Avoiding
this is a simple matter of generalizing the principles involved and taking into account the
requirements of all your databases and applications. Armed with these principles, you can
easily design a single data-restoration strategy that can apply to the entire infrastructure.
A good data-recovery strategy starts with the premise that no matter what is done, every database will need data restoration at some point in its life cycle. The role of a database administrator is to create an infrastructure plan that allows you to minimize how frequently data
recovery is needed, keep an eye out for developing problems before they develop into disasters,
and have a contingency for every possibility. The plan should also let you proceed quickly to
restoration when disasters do occur and promptly verify that the restoration was successful.
The next section reviews some basics about backup and restoration, as well as the different
types.
Backing Up Data
Redundancy is key to surviving a loss: a backup power supply, a second NIC, a standby or
failover server in another physical building, a hot site in another state, personnel trained in each
others duties, and so on. Here the emphasis focuses on a second, or even a third, copy of your
data and copies of data-entry worksheets so that you can recover to the millisecond of that loss.
A backup is a copy of data that is stored somewhere other than the hard drive of your computer, usually on tape or another device, such as a hard drive on another computer connected
over a local area network (LAN), somewhere that wont suffer the same consequences as the
primary site. There are three basic reasons to back up data:
The possibility of hardware failure. Despite significant advances in reliability, hardware
fails, often spectacularly and more often than not with an uncanny knack for happening
at exactly the wrong time. If you dont want to come to work one day and discover
that everything is missing because a hard drive went bad, you should always perform
regularly scheduled backups.
244 | Lesson 11
The chance of external disasters, whether natural or man made. No matter how
much redundant hardware you have in place, its not likely to survive a tornado, a
hurricane, an earthquake, a flood, or a fire. Although the possibility is slight, man-made
disasters, such as a terrorist attack or an act of war, can be catastrophic.
Human malevolence. A large number of data disasters can be traced back to insiders.
Far too often, employees who are angry with their boss or their company seek revenge by
destroying or maliciously changing sensitive data. This is the worst kind of data loss, and
the only way to recover from it is by having a viable backup.
Now that you know why you should back up your data, you need to learn how to do it.
TAKE NOTE
You can use the Database Maintenance Plan Wizard to schedule backups to run automatically. To access the wizard in Management Studio, expand Management, right click the
Maintenance Plans Folder, and then select Maintenance Plan Wizard.
LAB EXERCISE
TAKE NOTE
LAB EXERCISE
If you use a tape drive as a backup medium, it must be physically attached to the SQL
Server machine.
TAKE NOTE
Because each differential backup records all changes since the last full database backup, only
the most recent differential backup is required for restoration of data.
Differential database backups are best used with medium to large databases in between scheduled full database backups. As the length of time required to perform a full database backup
increases, performing differential backups obviously becomes more useful. Differential backups are particularly useful in speeding up data restoration times in databases where a subset of
data changes frequently and results in large transaction logs.
Performing only full and differential backups isnt enough. If you dont perform transaction
log backups, your database could stop functioning.
TAKE NOTE
When a transaction log becomes 100 percent full, users are denied access to the database
until an administrator clears the transaction log. The best way around this is to perform
regular transaction log backups.
246 | Lesson 11
LAB EXERCISE
CERTIFICATION READY?
The FULL, DIFFERENTIAL,
and TRANSACTION LOG
backup types are the
fundamental types of
backups. Know how they
relate to each other.
TAKE NOTE
If the tables and indexes are stored on separate files, the files must be backed up as a single
unit. You cant back up the tables and the associated indexes separately.
Restoring Databases
The purpose of all backups is to provide backup copies of data that can be used by restore
processes. It is essential that backups be designed with restoration in mind. It is equally essential for database administrators to be familiar with the various types and methods of restoring
data in databases.
Suspect or corrupt databases arent the only reasons to perform restores, though. You may, for
example, need to send a copy of one of your databases to the main office or to a branch office
for synchronization. You may need to recover from mistaken or malicious updates to the data.
These reasons, and many others, make it important for you to know how to perform restores.
248 | Lesson 11
For example, if you perform a full backup, then a differential backup, and then a transaction
log backup, you need to restore all three of those to bring the database back to a consistent
state. If you specify the RECOVERY option when restoring the differential backup, SQL
Server wont allow you to restore any other backups; you have told SQL Server in effect that
youre done restoring and that it should let everyone start using the database again. If you
have more than one file to restore, you need to specify NORECOVERY on all restores except
the last one.
SQL Server also remembers where the original files were located when you backed them up.
If you back up files from the D: drive, SQL Server restores them to the D: drive. This is great
unless your D: drive has failed and you need to move your database to the E: drive, or if you
need to change the location for any reason. In this instance, you need to use the MOVE . . .
TO option. MOVE . . . TO lets you back up a database in one location and move it to
another location.
Finally, before SQL Server will let you restore a database, SQL Server performs a safety check
to make sure you arent accidentally restoring the wrong database. The first thing SQL Server
does is compare the database name that is being restored with the name of the database
recorded in the backup device. If the two are different, SQL Server wont perform the restore.
For example, if you have a database named Accounting on the server, and youre trying to
restore from a backup device that has a backup of a database named Acctg, SQL Server wont
perform the restore. This is a lifesaver, unless youre trying to overwrite the existing database
with the database from the backup. If that is the case, you need to specify the REPLACE
option, which is designed to override the safety check.
LAB EXERCISE
In Exercise 11.5, youll disable a database, and in Exercise 11.6, youll perform a
simple restore.
This type of restore is useful if the entire database becomes corrupt and you need to restore
the whole thing. However, what if only a few records are bad, and you need to get back to the
state the database was in just a few hours ago?
TAKE NOTE
This process only works with transaction log backups, not full or differential backups.
In addition, youll lose any changes that were made to your entire database after the
STOPAT time.
Another type of restore comes in handy for VLDBs: piecemeal restores. Piecemeal restores
were implemented with SQL Server 2005 and augment the concept of partial restores
introduced in SQL Server 2000.
TAKE NOTE
A backup strategy is a plan that details when to use which type of backup. For example,
you can use only full backups, full with differential, full with transaction log backups, or
any other valid combination. Your challenge is to figure out which one is right for your
environment. Examine the pros and cons of each type of strategy.
250 | Lesson 11
full, you arent backing up the entire 500 MB every night, which is faster and requires less
disk space. A differential backup will often be a small percentage of the full backup size. This
could be only perhaps 10 MB of the 500 MB example database.
Another disadvantage of the full-backups-only strategy involves the transaction log. As you
saw earlier, the transaction log is cleared only when a transaction log backup is performed.
With a full-only strategy, your transaction log is in danger of filling up and locking your users
out of the database. To avoid this problem, you can set the recovery model to simple.
Another option is to perform the full backup and, immediately afterward, perform a transaction log backup with the TRUNCATE_ONLY clause. With this clause, the log wont be
backed up, just emptied. Then, if your database crashes, you can perform a transaction log
backup with the NO_TRUNCATE option. The NO_TRUNCATE option tells SQL Server
not to erase whats in the log already so that its contents can be used in the restore process.
This approach gives you up-to-the-minute recoverability as well as a clean transaction log.
TAKE NOTE
The first thing you should do in the event of any database failure is use the
NO_TRUNCATE option with the transaction log backup to save the orphaned log.
four hours (10:00 a.m., 2:00 p.m., and 6:00 p.m.) throughout the day during the week, and
differential backups every night. If your database crashes at any time during the week, all you
need to restore is the full backup from Monday, the differential backup from the night before,
and the transaction log backups, sometimes called incremental backups, up to the point of
the crash. This approach is fast and simple. However, none of these combinations work well
for a monstrous VLDB; for that, you need a filegroup backup.
TAKE NOTE
SQL Server can determine which transactions belong to each filegroup. When you restore
the transaction log, SQL Server applies only the transactions that belong to the failed group.
Managing reliable and secure backups across an enterprise can quickly become a complex
task. Therefore, its vital that you develop and test the backup and recovery strategy for your
database server infrastructure.
The recommended approach you should take when defining the backup and restore strategy
is to start with commonly accepted best practices for performing and documenting SQL
Server database backup and restore operations and then adapt them for the specific needs
of your organization.
252 | Lesson 11
When youre designing an organization-wide backup and restore strategy, follow these eight
key steps:
1.
2.
3.
4.
5.
6.
7.
8.
Among the many criteria you can use to categorize databases, you should include at least the
value, volatility, and size of the data, as described here:
Value of the data. Determine the significance of the data held in a database, and
identify those databases that are most critical. Take into consideration the role that
the data plays in the organization, the estimated cost of data loss, and the cost of data
unavailability during recovery. The end result may be categories such as mission-critical
databases, department-critical databases, and noncritical databases. Mission-critical
and department-critical databases may both require backups of transaction logs, but
noncritical databases may only require database backups.
Rate of change of the data. Very active databases may require a different backup-and-restore
strategy than that for relatively inactive databases. If the data changes frequently, youll find
that differential backups will be less useful than regular full and transaction log backups.
Size of the data. The size of a database can impact the options available for performing
backup and restore operations. You can use the size to determine the proper combinations of backups that you should take as part of your backup strategy. A large database
might be backed up only once per week or might have different filegroups backed up
each night. A smaller database might be fully backed up nightly.
254 | Lesson 11
The full recovery model covers the broadest range of failure scenarios and includes both database backups and transaction log backups. It also provides the most flexibility for recovering
databases to an earlier point in time.
If one or more data files are damaged, recovery can restore all committed transactions. Inprocess transactions are rolled back. In Microsoft SQL Server, you can back up the log while
a data or differential backup is running. In the Enterprise Edition of SQL Server, you can also
restore your database without taking all of it offline if your database is in full or bulk-logged
recovery mode.
The full recovery model supports all restore scenarios.
By logging all operations, including bulk operations such as SELECT INTO, CREATE
INDEX, and bulk-loading data, the full recovery model allows you to recover a database to the
point of failure or to an earlier point in time if youre using the Enterprise edition of SQL Server.
TAKE NOTE
R ECOVERY
M ODEL
BENEFITS
R ECOVER
IN T IME ?
Simple
Full
Bulk-logged
TO
P OINT
You should assign a recovery model for each category of database that youve identified. A good
rule of thumb for assigning a recovery model is to evaluate the requirements for each category:
Use the full recovery model for the most critical databases. This enables you to recover
data quickly and efficiently as long as you have the appropriate database and transaction
log backups available.
Use the bulk-logged recovery model if the database makes extensive use of bulk
operations to maximize performance.
Use the simple recovery model for databases with less critical recovery and performance
requirements. This lets you minimize the administrative overhead associated with these
databases, at the risk of losing changes made since the last backup was taken.
TAKE NOTE
CERTIFICATION READY?
Expect exam
questions requiring an
understanding of the
different backup options
and how the Recovery
Model setting relates to
your backup options. If
the Recovery Model is set
to Simple, how often are
transaction log backups
going to be done?
When a database is created, it has the same recovery model as the model database. You
can change the recovery model using either T-SQL or Management Studio. The T-SQL
command is ALTER DATABASE <database> SET RECOVERY { FULL | BULK_
LOGGED | SIMPLE }.
TAKE NOTE
You should always back up the master database before adding a new database or deleting an
existing database as well as prior to making any global configuration changes to SQL Server.
256 | Lesson 11
type of disaster that might affect your production location but close enough to enable
you to obtain your storage media in a reasonable time.
Use a secure method of delivering backup media to their storage destination.
Protect your backups by using strong passwords.
Back up your encrypted data to files and tape media.
TAKE NOTE
With the introduction of transparent data encryption (TDE) in SQL Server 2008, you now
have the choice of cell-level encryption as in SQL Server 2005, full database-level encryption by using TDE, or the file-level encryption (EFS) options provided by Windows. TDE
is the optimal choice for bulk encryption to meet regulatory compliance or corporate data
security standards. TDE works at the file level, which is similar to two Windows features:
the Encrypting File System (EFS) and BitLocker Drive Encryption, the new volume-level
encryption introduced in Windows Vista, both of which also encrypt data on the hard
drive. TDE does not replace cell-level encryption, EFS, or BitLocker.
TAKE NOTE
Dont include passwords in your documentation, because you then make your system only
as secure as the document in which the passwords can be found.
TAKE NOTE
When backing up and restoring databases, SQL Server provides online page checksum verification and backup and restore checksums. You should consider always using the CHECKSUM
option with the BACKUP command. You can use the BACKUP WITH RESTORE
VERIFYONLY T-SQL command to verify the validity of a backup without performing an
entire restore operation.
An excellent method of assuring that the databases stored in a backup dont contain any allocation, structural, or logical integrity problem is by using T-SQL to run the Database Console
Command (DBCC) DBCC CHECKDB prior to initiating BACKUP DATABASE. Doing so
initiates the performance of the following database operations:
Runs DBCC CHECKALLOC to check the consistency of disk-space allocation
structures for it.
Runs DBCC CHECKTABLE to check the integrity of all the pages and structures that
make up every table or indexed view in the database.
Validates the Service Broker data in the database.
Runs DBCC CHECKCATALOG to check for catalog consistency within the specified
database. Note that the database must be online.
Validates the contents of every indexed view in the database.
This means the DBCC CHECKALLOC, DBCC CHECKTABLE, and DBCC
CHECKCATALOG commands dont have to be run separately from DBCC CHECKDB.
Planning how to handle future unpredictable problems can greatly mitigate the negative
effects of these potential problems.
A database disaster recovery plan should be part of a broader disaster recovery plan for
your department or organizations entire IT infrastructure. Developing a good database
disaster recovery plan requires coordination with other departments within the organization,
including management, network administrative staff, and offsite storage operators.
Similarly, a business continuity plan (BCP) deals with the steps needed should a local
disruption or process change occur. As with a disaster recovery plan, the BCP has to be
coordinated with all participants to recover from the loss of key employees (implement
cross-training programs, perhaps), new acquisitions and mergers (start a business process
reengineering effort, perhaps), and/or a constant flood of new Microsoft updates and
products (analyzing the values of SQL Server 2008, perhaps).
CONTACT LIST
When an interruption occurs, you should have a list of key contacts readily available. These
are the people youll notify about the event and the current status of the system. You can
group contacts based on their role or need for information:
Key managerial personnel in your own department. These contacts are typically
responsible for notifying other members in the organization. In some cases, you may be
the one who has to notify others, so youll need a more comprehensive contact list.
Technicians and other staff responsible for helping recover the system. These
contacts include hardware service technicians, enterprise application service staff, and
possibly spare-part suppliers and transport agencies, for plans that require quickly
obtaining replacement machinery. You should also include backup personnel whom you
can notify in case you cant contact the first level of key individuals.
TAKE NOTE
You must also have a mechanism for providing access to the database administrators
password, should the database administrator (or the designated backup member of staff )
be unavailable. You should treat this password with all the sensitivity accorded to critical
financial data and protect it accordingly.
258 | Lesson 11
Those who need an alternative mode of operation while the problem is resolved.
This includes both personnel and departments affected by the disaster. For example,
if you detect that the database supporting a shipment-tracking system of the freightforwarding department has failed, you should notify the designated contact for that
department, who can in turn notify the customer service staff.
Just as important, make sure all contact information is up to date. Finding out it isnt should
happen before youre in the middle of an actual calamity. Dont get sloppy!
DECISION TREE
A comprehensive recovery plan must include key details for performing recovery in a wide
variety of circumstances. You should document the various circumstances that can arise and
the detailed steps to take to resolve each situation. For a particular type of disaster, you can
often consolidate many different recovery paths into a decision tree. A well-developed and
tested decision tree can help reduce errors and speed up the recovery process. Youll review
how to create a decision tree later in this Lesson.
RECOVERY SUCCESS CRITERIA
Make sure you have a set of criteria that verifies that a particular recovery process is complete
and successful. Dont think youre done after youve restored the databases for which you are
responsiblethats only the first step of the recovery. Make sure peripheral connectivity and
supporting items that applications require to access the databases are also available. The recovery process is finished only after the applications and anything else using the databases are
running as expected.
LOCATION OF BACKUPS, SOFTWARE, HARDWARE, KEYS,
AND ACTIVATION PROCESSES
You should document the locations of backups, software, hardware, serial numbers, softwareactivation keys or activation and configuration processes, and documentation describing how
to rebuild servers and reinstall software. Be sure to include information about software version numbers and any service packs required. If youre responsible for maintaining database
server hardware, you should also include locations of spare parts, such as replacement disks,
memory, and processors.
INFRASTRUCTURE DOCUMENTATION
The database disaster plan can contain server hardware specifications and configuration
information. However, there may also be related documents that it doesnt contain, such as
infrastructure diagrams and application process documents. You should make sure the disaster
plan specifies the location of the most recent versions of these documents.
CREATING A DISASTER RECOVERY DECISION TREE
The key to a good disaster recovery plan is anticipation and contingency planning. You should
assess the different types of disasters that can occur, analyze recovery needs, and provide
detailed steps for recovering from each situation. As you can imagine, the recovery processes
involved can be complex, and the data involved may be irreplaceable as well as critical. Taking
the wrong step during the recovery process can lead to an inordinate amount of lost time.
Adding to this area of concern is the simple fact that when disaster strikes, stress levels go up.
In most environments, stress is managed and activities are kept on the correct path by controlling the decision flow. If youve ever watched a disaster movie, you remember the scene
where the professionals trying to manage the event methodically go through their checklists.
One of the goals of disaster planning is to preempt decisions and ensure that they stay on the
path that will achieve the optimal results by providing a detailed set of steps to be performed
according to the circumstances.
These steps are usually captured in decision trees that can vary based on specific conditions.
At a high level, you should attempt to classify the types of potential database disasters, how
they can be detected, and what impact they can have on the availability of your databases.
Then, for each type of disaster, determine the proper order of recovery and the methods for
verifying that recovery is successful. The following sections provide some guidelines for developing a decision tree for a database disaster recovery plan.
CERTIFICATION READY?
Know the sequence
of the restore process
and when to use
the RECOVERY or
NORECOVERY options.
Identify the most critical databases. Classify the importance of databases in terms of
the losses that will be incurred if the databases are unavailable or the data they contain
becomes insecure. Consider any dependencies between databases. For example, if your
client database depends on a small configuration database, youll most likely have to
restore the configuration database first, even though the information that this database
contains isnt economically important.
Identify critical processes. Related processes can be just as important to restore as the
databases. Often, business applications involve more than one database, even more than
one service, such as SQL Server Integration Services, SQL Server Agent, and Message
Queuing. Some of these processes will be instrumental to the core business functionality
of your applications, whereas others may be less important.
List recovery steps in the correct order based on business needs. Identify the core
business processes that are most important and which must be recovered first. You
should consider recovering the databases that support these processes as the first priority.
In a large organization, you can also identify processes and their corresponding databases
that have secondary or even tertiary importance.
Establish recovery success criteria. Its important that you have a means to verify
the success or failure of each step in the recovery process. Make sure that personnel
260 | Lesson 11
performing each recovery operation have a written procedure and are required to test the
results of the step. The decision tree must include the expected results and the possible
actions to take if these results dont occur. You can document these further actions as
branches in the tree or references to other parts of the decision tree.
CERTIFICATION READY?
Disaster Recovery can
take many forms. Read
any exam question
carefully to identify what
situations a Disaster
Recovery Plan should
address.
LAB EXERCISE
Periodically validate the recovery plan. The time to specify the criteria for recovery
success is before a disaster occurs, not after. Steps you should take include the following:
Verify that a database restore was successful. It isnt enough to verify that you can
query the database. You must also verify that appropriate users can log on to the server
and access the correct data.
Verify that the correct (most recent) data was restored. Consider including T-SQL
scripts in the plan that can verify the timeliness of the restored data. This means you
need to verify that the most recent or up-to-date data is present.
Determine and communicate the extent of any data loss. No matter what you do,
you still may lose some data that was entered or changed during a certain period of
time. This can happen, for example, if youre using log shipping and you werent able
to save the active part of the transaction log before the disaster.
Validate recovery-success criteria. Have clear criteria that you can apply that test the
resulting databases for correctness. Make sure the recovery plan supports the required
applications. In the event of a catastrophic failure that extends beyond the database
say, a building fireyoull need to integrate your activities with the organizations
recovery plan.
Validate the contact list, software locations, and hardware locations. Often the
simplest parts of a recovery plan are the elements that you overlook. Apart from the
technical steps involved in recovering the data, you must ensure that the supporting
information is up to date.
Conduct periodic checks to validate that people in the contact list still have the same
phone or extension number and hold the same position in the organization. You must
also ensure that backup hardware and software are located where you expect to find them.
Revise the recovery plan based on periodic rehearsals and validations. Database
recovery plan rehearsals, along with actual disaster recoveries, give you essential feedback about the usefulness and relevance of your recovery processes and documentation.
Incorporating that feedback into the recovery plan document is the most effective way of
keeping your plan up to date and keeping you prepared.
Rehearse and revise the recovery plan when the infrastructure changes. An organizations infrastructure doesnt stand still. When you add new databases, applications,
hardware, or software, or when you upgrade to new releases of software, its important to
verify that the recovery plan still works and to update it as necessary.
In Exercise 11.7, youll develop a disaster recovery decision tree.
S K I L L S U M M A RY
In this Lesson, youve examined the topic of designing a data-recovery solution for
databases. Throughout, youve learned how to go about deciding which steps you should
take to determine what data-recovery technologies to use based on business requirements. Youve learned how to analyze business and assess alternative techniques and
models to save copies of critical business data for archiving and how to plan for data
archival access.
Youve learned how to select from different backup formats and determine the number of
devices to be used for backups; how to specify what data to back up; and the frequency,
techniques, types, and recovery models too employ.
Key to the Lesson has been developing an understanding of how to create recovery plans. You
learned the questions to ask, the methods to utilize, and the procedures to follow. Youve
discovered that in the midst of a seeming catastrophic failure, something as simple as a
well-thought-out decision tree can save you and your organization countless hours of time
and ensure your ability to recover from all but the most egregious of problems.
262 | Lesson 11
Know how to perform full, differential, transactional, and filegroup backups. You need to
know the T-SQL syntax and SQL Server Management Studio methods of performing the
various backups. You should also focus on the advantages and disadvantages of the types
of backups.
Know about the various database recovery models. You need to know when to use the
simple, bulk-logged, or full recovery model and the options, advantages, and disadvantages of each.
Know how to restore a database. You need to know the T-SQL syntax and Management
Studio methods for restoring databases.
Know how to recover from a complex crash scenario. You need to know how to recover
from complete crashes of SQL Server, as well as from a crashed or suspect database.
Know how to design a decision tree. You need to know how to design a disaster recovery
tree and what elements to include.
Knowledge Assessment
Case Study
Waves Styles on George
Waves Styles on George is a large fashion and apparel service agency serving as a
wholesaler for approximately 14,000 subagencies and outlets over a broad geographic
area. The company is headquartered in the city of Trevallyn, which also serves as
northern headquarters, with 407 employees. Three branch offices are located in
Devonport (eastern operations), Ravenwood (western), and Meriwether (southern).
Planned Changes
The company wants a complete disaster recovery plan overhaul and a reevaluation of its
backup strategy.
Existing Infrastructure
The company has three existing SQL Server 2005 computers running with default
instances, which contain the following databases:
WGServer1: Accounting and HumanResources
WGServer2: Customer
WGServer3: Contractor, Orders, and Parts
Business Requirements
Users need to be able to access their data at any time of the day or night. The Customer
database must not fail when a single hard disk on the server fails. The Customer database is very volatile, with numerous changes daily during business hours of 09:00 to
18:00. Most of the changes occur during the afternoon hours. Very few changes are
made during nonbusiness hours. Business requirements allow for up to one hour of data
loss. Requirements state that no more than six backups should be required to recover
any given database. Following tests of different backup scenarios, it was determined that
full backups were not to be done during business hours and differential backups should
be performed only once during business hours.
Technical Requirements
The existing named instance configuration cant be changed because its mandated by
the disaster recovery plan.
The recovery model for the Orders database must be full recovery.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions:
1. You are asked to design the backup schedule for the Customer database. Fill in the
blanks of the following table using these backup types (each selection may be used once,
more than once, or not at all): full, differential, copy, transaction log, incremental.
S CHEDULE
BACKUP TYPE
264 | Lesson 11
6. You need to design a method for testing and verifying that future backups of
WGServer2 can be restored and that the databases stored in the backups do not
contain any allocation, structural, or logical integrity problems. Which two actions
should you perform?
a. Restore the backups to another SQL Server computer.
b. Run DBCC CHECKDB on the original databases.
c. Run DBCC CHECKDB on the restored backups.
d. Use the RESTORE VERIFYONLY command.
7. You need to be able to restore the Parts database at any given time, but it is a very large
database with many inserts and updates; a full backup takes nine hours. You implement
the following strategy: You schedule a full backup every week, with differential backups
every night. You set the recovery option to simple to keep the log small, and you schedule transaction log backups every hour. Will this solution work?
a. This solution works very well.
b. This solution will not work because you cannot combine differential backups with
transaction log backups.
c. This solution will not work because you cannot schedule transaction log backups
with full database backups.
d. This solution will not work because you cannot schedule transaction log backups
when you have selected the simple recovery model for a database.
8. You have three filegroups (FilesA, FilesB, FilesC) in the HumanResources database. You
are rotating your filegroup backups so that each filegroup is backed up every third night.
You are also doing transaction log backups. The files in FilesB get corrupted. Which
of these steps would you take to restore the files? (Choose all that apply, and list your
answers in the order the steps should be taken.)
a. Restore the transaction log files that were created after the FilesB backup.
b. Restore the FilesB filegroup.
c. Back up the log with the NO_TRUNCATE switch.
d. Restore the entire HumanResources database.
9. As discussed previously, Waves Styles on George has a database called Customers. You
are performing full backups every night at 23:00 and differential backups at 12:00 and
19:00. On Tuesday at 17:45, a user deletes all the rows of the table. You discover the
error at 21:00. What is the correct way to restore the Customers database?
a. Restore the full backup from Monday night. Restore the 19:00 differential backup
until 17:44.
b. Restore the full backup from Monday night. Restore the differential from Tuesday
until 12:00.
c. Restore the full backup from Monday night. Restore the differential from 12:00.
d. Restore the full backup from Monday night. Restore the differential from 19:00.
10. You need to configure the Orders database to meet the technical requirements. Which
T-SQL statement should you use?
a. ALTER DATABASE Orders SET RECOVERY SIMPLE
b. DBCC CONFIGDB BACKUP TYPE Orders SIMPLE
c. ALTER DATABASE Orders SET RECOVERY FULL
d. ALTER DATABASE Orders SET RECOVERY MODE TO FULL
L ESSON
12
L E S S O N S K I L L M AT R I X
TECHNOLOGY SKILL
EXAM OBJECTIVE
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
Foundational
KEY TERMS
archive: A repository containing
historical records that are
intended for long-term
preservation.
format: The organization of data
stored on some form of media.
This could be a SQL Server
backup format, a simple TXT file
containing comma-separated
value (CSV) data, or some other
form of organization of the data.
265
266 | Lesson 12
One of the results of a well-designed and expertly crafted database is that it fills with
data. Over time, the sheer amount of data may begin to overwhelm the database system.
At the same time, not all of the data needs to be instantly available. Trying to keep it all
where it can be obtained immediately may serve the opposite goal and begin to degrade
your database, making accessing records more difficult than necessary.
Youve probably seen a similar phenomenon in your day-to-day activities. You may have
started by keeping all your financial records, receipts, bank statements, cancelled checks, and
the like readily available in a file drawer or box. After a few years, the volume of material
probably convinced you to toss out some of the material you no longer need. The remainder
of the older stuffsuch as five-year-old tax returnsyou may have removed from the current
file drawer, inventoried, and placed in a cardboard box in your attic for future reference.
In doing so, you went through all the steps that describe a data-archiving strategy and
solution. And you thought this Lesson was going to be difficult!
In this Lesson, youll first review the whys and wherefores of data archiving and make sure
youre clear on why such a system needs to be part of any database infrastructure design.
Then, youll be introduced to the fictional company Yanni HealthCare Network, which youll
use throughout this Lesson to illustrate how to visualize data-archiving concepts. Finally,
youll go through the basic process of designing a data-archiving solution, including determining business and regulatory requirements and what data will be archived, selecting a storage
format, developing a data-movement strategy, and designing a replication topology if replication is used.
Although there are many advantages to archiving historical data, archiving isnt a cure-all for
whatever ails your system. Archiving cant provide a solution for issues such as poorly chosen
indexes, design flaws, improper file placement, and inadequate maintenance and hardware.
Typically, data archiving improves the performance of database servers. However, the results
may sometimes be disappointing. For example, if the amount of data to be archived is relatively small, it may not be worthwhile to archive it, and archiving it may not produce the
desired results in terms of improved performance.
Although archiving data can be a complex process, designing an archiving solution is relatively
simple if you approach the problem in a systematic manner. At a minimum, a data-archive
plan defines both the scope of archiving and the architecture of the archived data. Once you
have the process down, youll be able to apply the same steps and procedures to nearly any
situation and come up with a plan that meets your needs.
In creating a data-archive plan, you should take the following steps:
1. Determine business and regulatory requirements.
2. Determine what data will be archived.
3. Select a storage format and media type.
4. Develop a data-movement strategy.
5. Design a topology if replication is used.
268 | Lesson 12
accountants, and the research staff are insistent that all information be both retained
online and archived. Finally, the organization has sufficient budget to purchase one or
more new servers for storing the archived data.
Throughout this Lesson, youll use this scenario as a tool to show how to design a dataarchiving solution.
Business regulations may stipulate the length of time that data must be accessible online. For
example, in many countries, banks are required by law to maintain certain customer data
online for a specific number of years. Health care providers are also subject to laws and regulations related to maintaining confidential information, often for long periods of time. Other
businesses, such as manufacturing and retail sales organizations and government agencies, may
also need to comply with certain regulations. These regulations may influence data-archiving
requirements in varied ways and lead to interesting and creative archive solutions. You must
consider the impact of regulatory requirements when determining what data can be stored
offline and how quickly it must become available online when requested.
Another consideration is how much of the data you need. Users may not need detailed data
after a certain period. In such cases, you can maintain summary tables online and archive the
detailed data to offline storage.
Applying these concepts to the Yanni HealthCare Network scenario, you can see that combined
business and regulatory requirements require you to keep all the laboratory data in some
manner. The level of detail required isnt clear, and this is the sort of question you should
discuss with the key stakeholders and management at the hospital. In these discussions, youll
be expected to listen and provide solutions. Youll also be expected to explain the impact of
these requirements on the database system and any performance issues you foresee.
You need to consider one other type of requirement in your design: the accessibility of data.
Some data needs to remain online and immediately available. Other data can be removed
from immediate access but may need to be readily accessible in a short period or long period
of time. In reviewing and creating your archival data plan, you need to consider these factors
as well as the acceptable turnaround time. Once youve done that, you can stratify the data
based on relevant time frames. Accessibility requirements and turnaround time also determine
the storage formats and media you can use for archiving data.
Finally, you need to accurately assess the requirements against what the stakeholders want and
what the stakeholders need. Users often demand that historical data be maintained online
because they dont want to risk losing access to it. However, after the data is archived, they
rarely access the data. This perception of risk to accessibility can lead key stakeholders to
be reluctant to move data offline. One of your tasks as a database administrator must be to
accurately scope what data needs to be archived and to determine the impact on accessibility.
When proposing a data-archive strategy, you should communicate the benefits of archiving
the data and share a plan for ensuring the security and accessibility of the archived data.
Based on the requirements spelled out in the Yanni HealthCare Network scenario, you
need to keep all existing and future data. The users want to be able to access five years of
data online. Governmental regulations require maintenance of data for 25 years, and your
management team wants to retain all data forever.
You review the data and determine that maintaining five years of data is an expensive and
resource-intensive use of assets. You do a study that indicates only 1 percent of all queries
specify data greater than three years old. You bring this information to the attention of the
stakeholders; and after examining the balance between cost, performance, and need, all sides
agree that data three to five years old can be maintained elsewhere, provided the turnaround
time is less than three hours. The result is a structured data-archive plan for accessibility based
on age of data, as shown in Table 12-1.
As youll see later in this Lesson, accessibility requirements also influence the structure of
archival data and affect the planning for data-storage formats and media.
CERTIFICATION READY?
Imagine various business
scenarios and how to
meet unique needs. For
example, you have four
distant warehouses and
corporate headquarters
needs to query the
archived data once
a week. Change the
scenario to storing
the data at corporate
headquarters but analysts
only query it once a
year. Keep tweaking the
parameters and redesign
appropriately until you're
comfortable with any
situation.
A CCESSIBILITY
REQUIREMENT
A GE
OF
D ATA
Immediate access
3-hour access
Data more than 3 years old but less than 6 years old
24-hour access
48-hour access
270 | Lesson 12
CERTIFICATION READY?
Imagine various business
scenarios and answer
the questions: How long
must data be stored?
What table attributes
must be maintained? Is it
better to denormalize the
data? What answers will
users seek? Should you
create a cube instead?
two years worth of data online, you can archive data at either monthly or weekly intervals. If you archive monthly, then 25 months of data (2 years plus 1 month) would exist
online just prior to the monthly archival process.
REF
Partitioned tables. You can use fully partitioned tables to structure archival data.
Partitioned tables were introduced with SQL Server 2005 and are more effective than
the older union-partitioned views for managing very large tables and indexes. Partitioned
tables are also easier to maintain than union-partitioned views. It can be difficult to find an
appropriate check constraint on which the partition can be based with union-partitioned
views, and queries across the views dont always select the appropriate partition correctly.
You can place partitioned tables and their indexes in separate filegroups. In addition, you
can automatically repartition data among tables. You can also switch tables in and out
of a partition. After a table is switched out of a partition, you can move the table and its
index to the archival destination.
Normalized tables. Archiving related data together keeps the historical context of the data.
Normalized tables can be used to structure archival data and maintain historical content. If
you use normalized tables, a key consideration is to make sure the tables can accommodate
changes in lookup values or related tables. One way to accomplish this is to add date-range
validity to the normalized tables. You can then specify the date ranges for valid lookup
values. Note that archiving relational data often requires the archiving of additional data
involved with foreign keys. Normalized data requires these key relationships.
Denormalized tables. If youre unable to archive all related data together, you can use
denormalized tables to preserve the historical context of the data. Denormalized tables
store actual values rather than references to the current data. Therefore, these tables are
most useful for optimizing queries that involve complex joins.
In addition to denormalized tables, you can use indexed views to denormalize data.
Because denormalized tables persist data physically, you can retrieve data from them
more quickly than from indexed views. However, denormalized tables require additional
disk space. Denormalized tables also must be periodically rebuilt and arent automatically
updated like indexed views.
Summary tables. You may not need to maintain detailed data after a certain period. In
such cases, you can keep summary tables online and archive the detailed data and store
it offline. For example, you may have a database that stores monthly sales revenue by
product. It may be possible to remove and archive the detailed data while maintaining
only the monthly summaries.
The time frame for accepting updates to archived data. This, in turn, may depend on
regulatory requirements.
The rules for archiving.
Storage costs. When developing a structure for archival data, you must be mindful of the
hardware, media, and often, software costs for storing the data. As a rule of thumb, storing archival data online has been more expensive than storing the data offline. This may be
changing. If you choose to use denormalized tables for your archived data, additional disk
space will be needed with concomitant increases in storage costs. You can reduce hardware
costs by keeping only the summary data online and storing detailed data offline. The hardware
used for creating offline storage media then becomes a factor along with the per unit cost of the
offline media as well as any special software for writing to and reading from the media.
CERTIFICATION READY?
Imagine various business
scenarios and list the
considerations a plan
must include. Is there
a networking element?
When are data no longer
needed?
Offline storage can involve hidden costs such as transportation or retrieval costs charged by
offsite couriers. In addition, you need to ensure that the security of the data that is stored
offline isnt compromised. Its also possible that in the event of a major disaster, access to
archived data may not be as smooth as hoped. In the aftermath of the 9/11 attacks on New York
and Washington, DC, as well as Hurricane Katrina in New Orleans and the Gulf of Mexico, offsite
data-storage centers were overwhelmed by demands for archival and replicated current data.
If the structure or format of archival data differs from the source online data, additional
expenses may be incurred for developing applications and reports to access the archived data.
Backups and archiving of historical data require the selection and use of storage media
and storage format types. This section provides information on how to make appropriate selections of these topics.
Storage format refers to the logical structure of data on a type of physical media that is used
to store the archived data.
Examples of storage format could be SQL backup files, CSV data extracts, or TXT files from
BCP. The physical media can be disk, tape, optical storage such as CDs and DVDs, or other less
frequently used types of media. Depending on your requirements, you can store archived data on
tape or on low-cost magnetic or optical media. With disk costs falling, there is an increasing movement toward storage on disk. You can also store archived data in a separate database on the server
that hosts the production database. This would be an example of storing archival data in SQL
Server database format. Alternatively, you can use a dedicated server to store archived data. The
choices for storage media and format are influenced by the structure and accessibility requirements
of the archival data. Each type of media and format has different characteristics with respect to
cost, accessibility, shelf life, reliability/durability, security, and changing technology:
Cost. If you need to archive a large volume of data, the cost of storage can be significant.
As a rule of thumb, for large amounts of data, tapes are cheaper than disks or optical
media; but disk prices keep falling, and in some instances disks may make better sense.
Accessibility. If the archived data must be quickly accessible, you should normally
use some form of online storage. Traditional offline media such as tape or CDs can be
accessed quickly if you invest in some form of robotic media library. This could be a
considerable extra-hardware expense.
Shelf life. Shelf life refers to the lifetime of the storage media. Many types of digital storage media, such as DVDs or LTO tapes, are relatively new, and their shelf life may not be
easily determined. If you opt to keep the archive media in your control, make sure you
follow vendor recommendations for storing your archived data in proper environmental
conditions (for example, store tapes in a cool, dry place). If you use an external vendor for
storage, check from time to time to make sure the data is held properly. Also consider the
shelf life of any required hardware. If data was archived to reel-to-reel tape 20 years ago,
can you get a working reel-to-reel 9-track tape drive that can read the archival tapes?
272 | Lesson 12
Reliability and durability. You must take into account the relative durability and
reliability of the media used. Some types of media are more sensitive to handling and usage
than others and may degrade faster. For example, tapes tend to deteriorate more easily than
disks or optical media. Its worth assessing the differences in order to ensure that archived
data is readable from archival media. If the ability to retrieve data from old media is critically important, you should have multiple redundant copies of the data and periodically
perform read testing to ensure that the media can be read. Having a redundant copy then
allows you to make a fresh copy should it be determined that any one copy is unreadable.
Security. There are many ways to provide for encryption. However, the administrative
overhead and third-party products involved vary. For example, there are third-party
products for encrypting data on both tapes and disks. In addition to encrypting archival
data, you should ensure that the data is stored in a secured location.
Changing technology. Once you have your plan in place, you need to be ready to adapt
it to changes in technology, because there may be shifts in relative costs of items. For
example, the authors of this book have gone from storage of archive material on floppy
disk to hard drive or zip drive to CD to DVD or SANs. Its likely that such technological
innovation will continue unabated, and youll need to be prepared to revise your plans.
Now, apply the previous discussion to the Yanni HealthCare Network scenario and design a
table that shows the archival design as well as summarizes the storage formats and media (see
Table 12-2). Note that the business and regulatory requirements have led you to conclude
that tape isnt the best approach for data greater than six years old. Although tape may be an
appropriate option in most cases, the need to conduct data studies using the historical data
leads to a trade-off between the more expensive but more manageable archive server with data
on disk, as opposed to tape.
Table 12-2
Data-archiving strategy:
Storage format/media
accessibility
R EQUIREMENT
A GE
Immediate access
3-hour access
24-hour access
48-hour access
OF
D ATA
CERTIFICATION READY?
Imagine various business
scenarios and justify a
storage solution best
meeting the trade-offs
between cost, longevity,
access speed, reliability,
security, and building
requirements. Do you
need a remote hot site?
274 | Lesson 12
All forms of data replication involve multiple database servers. A fundamental step in developing a replication process is to design the topology of the involved servers and how the data
will be replicated across this topology.
The sole purpose of replication is to copy data between servers. Several good reasons exist for
having a system that does this:
If your company has multiple locations, you may need to move the data closer to the
people who are using it.
If multiple people want to work on the same data at the same time, replication is a good
way of giving them that access.
Replication can separate the functions of reading from writing data. This is especially
true in OLTP environments where reading data can place a load on the system.
Some sites may have different methods and rules for handling data (perhaps the site is a
sister or child company). Replication can be used to give these sites the freedom of setting their own rules for dealing with data.
Mobile sales users can install SQL Server on a laptop, where they may keep a copy of
an inventory database. These users can keep their local copy of the database current by
connecting to the network and replicating.
Youll probably be able to come up with even more reasons to use replication in your enterprise.
Another application of replication involves archival data. At first, this may seem counterintuitive. Replication is normally associated with synchronizing live (active) databases. Archival
data could be viewed as historical and static and not a good candidate for replication, but that
isnt always the case.
There may be business reasons or regulatory requirements that mandate the existence of more
than one copy of the same archival data. Securities and Exchange Commission regulations
17a-3 and 17a-4, for example, stipulate that an exact duplicate of archived electronic records
must be stored separately from the original. Because archival data must be updated with
newly archived records, even if infrequently, replication is an easy way of ensuring that the
data remains synchronized between different locales and copies of archived databases.
Replication also addresses both regulatory compliance and disaster-recovery needs. A key
question youll have to assess is whether replication of the archival data is correct for your situation.
You can also use replication to provide higher availability of archival data. With replication,
if one archival site isnt available for any reason, then another site can be used to service the
request. When a dataset is archived, several options are available for replicating this data for
high availability, as youll see shortly.
Replication is most appropriate for distributing copies of data among databases. Its also the tool
of choice for supporting multisite updates and mobile users who are occasionally connected.
Although replication provides limited support for data transformation, its best suited for circumstances where the structure of the data on the publisher and on the subscribers is the same.
Publication
Article
Article
Article
Publisher
Contains original
copy of data
Distributor
Collects changes
from publishers
Subscriber
Receives a
copy of data
TAKE NOTE
CERTIFICATION READY?
Imagine various
business scenarios.
What replication
strategy works best
for each? When can
other technologies
(mirroring, copying
to another location,
distributed transactions,
backup and restore) be
better solutions than
replication?
Publisher. In SQL Server terminology, a publisher is a server with the original copy of
the data that others needmuch like the newspaper publisher has the original data that
needs to be printed and distributed. The data is organized into publications, which consist of smaller datasets called articles.
Distributor. Newspapers need carriers to distribute the newspaper to the people who
have subscribed, and SQL Server needs special servers called distributors to store and
forward initial snapshots of publications and distribute them to subscribers. Distributors
can also store transactions that need to be sent to subscribers.
Subscriber. A subscriber is a server with a database that receives copies of publications
from a publisher. A subscriber is akin to the people who need to read the news and
therefore subscribe to the newspaper.
The analogy goes even further: All the information isnt lumped together in a giant scroll and
dropped on the doorstepits broken into publications and articles so that its easier to find
the information you want to read. SQL Server replication follows suit:
Article. An article is data from a table that needs to be replicated. You probably dont need
to replicate all the data from the table, so you dont have to. Articles can be horizontally
partitioned, which means not all records in the table are published; and they can be
vertically partitioned, which means that not all columns need to be published.
Publication. A publication is a collection of articles and is the basis for subscriptions. A
subscription can consist of a single article or multiple articles, but you must subscribe to
a publication as opposed to a single article.
Now that you know the three roles that SQL Servers can play in replication and that
data is replicated as articles that are stored in publications, you need to learn the types
of replication.
276 | Lesson 12
distribution of publications for similar reasons, so that the data gets to the subscribers when
its needed.
There are three basic types of replication: transactional, snapshot, and merge (all of which are
discussed in the following sections). Consider the following key factors when choosing a replication type:
Autonomy. The amount of independence your subscribers have over the data they
receive. Some servers may need a read-only copy of the data, whereas others may need to
be able to make changes to the data they receive.
Latency. How long a subscriber can go without getting a fresh copy of data from the
server. Some servers may be able to go for weeks without getting new data from the publisher, whereas other instances may require a very short wait time.
Consistency. The most popular form of replication may be transactional replication,
where transactions are read from the transaction log of the publisher, moved through
the distributor, and applied to the database on the subscriber. This is where transactional
consistency comes in. Some subscribers may need all the transactions in the same order
they were applied to the server, whereas other subscribers may need only some of the
transactions.
Once youve considered these factors, youre ready to choose the replication type that will
work best for you.
When data is updated at a subscriber, the update is sent to the publisher when next connected.
The publisher then sends the data to other subscribers as they become available.
Because the updates are sent asynchronously to the publisher, the publisher or another
subscriber may have updated the same data at the same time, resulting in conflicts when
updates are applied. All conflicts are detected and resolved through a conflict-resolution
policy defined when the publication is created.
TAKE NOTE
Snapshot replication
is principally used to
establish the initial set
of data and database
objects for merge
and transactional
publications.
A good example of where to use this type of replication is in a department store chain that
has a catalog database. The headquarters keeps and publishes the master copy of the database
in which changes are made. The subscribers can wait for updates to this catalog for a few days
if necessary.
The data on the subscriber should be treated as read only here as well because all the data
will be overwritten each time replication occurs. This type of replication is said to have high
latency, high autonomy, and high consistency.
Snapshots are created using the Snapshot Agent and stored in a snapshot folder on the publisher.
Snapshot Agent runs under SQL Server Agent at the distributor and can be administered
through Management Studio.
278 | Lesson 12
occurs. This type of replication has the highest autonomy, highest latency, and lowest transactional
consistency.
Publication database
Distribution database
Subscription databases
msdb database and master database at the publisher, distributor, and all subscribers
Script the replication topology. All replication components in a topology should be scripted
as part of a disaster-recovery plan. The scripts can also be used to automate repetitive tasks.
A script contains the T-SQL system stored procedures necessary to implement the replication
component(s), such as a publication or subscription. Scripts can be stored with backup files
to be used in case a replication topology must be reconfigured.
TAKE NOTE
Scripts can be created in a wizard (such as the New Publication Wizard) or in SQL Server
Management Studio after you create a component. You can view, modify, and run the
script using SQL Server Management Studio or sqlcmd.
A component should be rescripted if any property changes are made. If you use custom stored
procedures with transactional replication, a copy of each procedure should be stored with the
scripts and the copy should be updated if the procedure changes.
Understand replication performance. Before replication is configured, you need to review
and understand the factors that affect replication performance and how to manage them:
Establish a performance baseline. After replication is configured, you should use Replication
Monitor and System Monitor to determine how replication behaves with your typical workload and topology. Determine typical values for the following five dimensions of replication
performance:
Latency. The amount of time it takes for a data change to be propagated between nodes
in a replication topology
Throughput. The amount of replication activity (measured in commands delivered over
a period of time) a system can sustain over time
Concurrency. The number of replication processes that can operate on a system
simultaneously
TAKE NOTE
Latency and throughput are most important in transactional replication because transactional replication generally requires low latency and high throughput. Concurrency and
duration of synchronization are most relevant to merge replication, because systems built
on merge replication often have a large number of subscribers, and a publisher can have a
significant number of concurrent synchronizations with these subscribers.
Create thresholds and alerts. Replication Monitor allows you to set a number of thresholds
related to status and performance. Its recommended that you set the appropriate thresholds for
your topology; if a threshold is reached, a warning is displayed, and, optionally, an alert can be
sent to an e-mail account, a pager, or another device. Note that SQL Server replication provides a number of predefined alerts that respond to replication agent actions. Administrators
can use these alerts to stay informed about the state of the replication topology.
Monitor the replication topology. Monitoring a replication topology is an important part of
deploying replication. Because replication activity is distributed, its essential to track activity
and status across all computers involved in replication. Replication Monitor is the most important tool for monitoring replication, allowing you to monitor the overall health of a replication
topology. T-SQL and Replication Management Objects (RMO) provide interfaces for monitoring replication. System Monitor can also be useful for monitoring replication performance.
CERTIFICATION READY?
Imagine various
business scenarios.
Under what conditions
do merge, snapshot,
and transactional
replication make sense?
For example, what if
you have unreliable
cross country network
connectivity? What if
local host users keep
changing the archived
data? What if the host
servers keep crashing?
Validate data periodically. Validation isnt required by replication, but its recommended that
you run validation periodically for transactional replication and merge replication. Validation
lets you verify that data at the subscriber matches data at the publisher. Successful validation
indicates that at a point in time, all changes from the publisher have been replicated to the
subscriber (and from the subscriber to the publisher, if updates are supported at the subscriber),
and the two databases are in sync.
Adjust publication and distribution retention periods if necessary. Transactional replication and merge replication use retention periods to determine, respectively, how long
transactions are stored in the distribution database, and how frequently a subscription must
synchronize. You should monitor your topology to determine whether the current settings
require adjustment. For example, in the case of merge replication, the publication retention
period (which defaults to 14 days) determines how long metadata is stored in system tables.
If subscriptions always synchronize within five days, consider adjusting the setting to a lower
number to reduce the amount of metadata and possibly provide better performance.
Understand how to modify publications if application requirements change. After youve
created a publication, it may be necessary to add or drop articles or change publication and
article properties. Most changes are allowed after a publication is created, but in some cases,
its necessary to generate a new snapshot for a publication and/or reinitialize subscriptions to
the publication.
280 | Lesson 12
LAB EXERCISE
subscribers. For example, if you place the publisher in one location and all the subscribers in
another location, you can place the distributor near the subscribers to reduce the longdistance network traffic across slower speed WAN links.
Select a replication type. The degree of consistency between the database on a publisher and
the replicated database on a subscriber depends on whether you use snapshot, transactional,
or merge replication. For example, if you use snapshot replication, the subscriber receives
periodic snapshots of the publication stored on the publisher. As a result, the database on
the subscriber is inconsistent with the database on the publisher. Conversely, transactional
replication distributes the publication to the subscriber with low latency. Therefore, the
database on the subscriber is more consistent with the database on the publisher.
Create a replication topology diagram. A replication topology diagram helps you
understand the flow of data between replication partners. If a diagram of the existing
replication topology isnt available, you must create a diagram and update it each time you
change the topology. The diagram should depict all the servers involved in replication and
the databases they host, the role of the servers, and the direction of data flow between
the servers.
For each database, identify the direction of replication. If a table exists in several databases,
ensure that the table isnt replicated multiple times through different paths. To identify
the fastest path between replication partners, consider the speed of the network connection
and its usage level.
Determine the distributors. Determine the placement of a distributor with respect to
the corresponding publisher. You can place the distributor and the publisher on separate
servers, or you can place them on the same server.
Determine subscribers. Based on the data requirements of each subscriber, you can
identify the publications it requires. In addition, you must determine whether the
subscriber should be allowed to modify the published data and return the modified data
to the publisher. In general, this isnt a concern with archival data, because the subscriber
is the archive server, which should not ever convert the original data on its own.
Choose either push or pull subscription. If you configure the distribution agent on
the distributor, the replication process is called push subscription. Conversely, if you
configure the distribution agent on a subscriber, the replication process is called pull
subscription. When determining whether to use push or pull subscription, you should
consider the number of subscribers and the memory and CPU requirements of each
subscriber. Typically, push subscription is used to minimize the resource utilization on the
subscribers. If you want to offload the distribution agent overhead from the distributor to
the subscribers, pull subscription is a better choice.
Determine the security requirements. When determining the security requirements of
your replication topology, make sure to identify security accounts for replication agents
and the File Transfer Protocol (FTP) access rights for replication.
In Exercise 12.1, youll learn how to apply the replication principles youve learned about in
this Lesson to the Yanni HealthCare Services scenario.
S K I L L S U M M A RY
In this Lesson, youve examined the topic of archiving data as it relates to database infrastructure.
You learned the role of business, regulation, and accessibility requirements and how they
shape the ultimate design of the data-archiving plan. Youve learned how to identify data for
archiving and how to plan for data-archive access.
Throughout the Lesson, youve seen how to select from different storage formats and develop
a data-movement strategy. Additionally, youve become familiar with the role of replication in
archiving data and how to design a replication topology.
Most important, in this Lesson, as in the rest of the book, youve learned that database infrastructure design is a complex series of interactions involving myriad variables. Youve also learned that
this seemingly overwhelming and difficult process is manageable. All it requires is a basic
understanding of SQL Server, an ability to grasp the elements, and a systematic approach to the
challenges they present. In the final analysis, designing a database infrastructure (or any element
of it) requires that you understand your constraints and requirements and then follow a careful
process to achieve your goal: a well-designed SQL Server database server infrastructure.
For the certification examination:
Understand the different types of replication. Know how replication works and when the
different types are best used. Be sure to understand latency, autonomy, and consistency.
Understand business and regulatory requirements. Know what the different business and
regulatory requirements are and how they affect your archival storage needs.
Understand the advantages and disadvantages of different storage media and formats. To
effectively select from a number of options, you need to know the different storage types,
the pros and cons of each, and when theyre most appropriate. For example, tape and optical
media are low-cost, long-term storage choices for data that is never queried, but they are
not a good option for data that needs to be accessed in a very short period of time.
Knowledge Assessment
Case Study
Developing an Archive Plan
Thylacine Savings & Loan Association is a large financial institution serving
approximately 1.6 million customers over a broad geographic area. The company is
headquartered in the city of Trevallyn, which also serves as northern headquarters,
with 407 employees. Three branch offices are located in Stratford (Eastern operations),
Belleville (Western), and Rock Hill (Southern).
The company currently has a 3 TB OLTP database that tracks more than 2 billion
transactions each year. The main database for all transactions and operations is located
in Trevallyn. Regional databases contain deposit/withdrawal information only and the
headquarters database is updated daily from the regional offices.
Thylacines departmental database servers are dispersed throughout the headquarters
location. The company is currently experiencing a 4 percent annual growth and plans
to expand into four new markets at the rate of one new market every two years. The
282 | Lesson 12
database is growing at a rate of 6 percent per year and will exceed available hard-disk space
in the future. Additionally server capacity is overloaded, resulting in poor performance
and long delays. A large portion of the database data is historical information.
Youve been asked to develop a data-archiving plan for their ATM transactions. Once an ATM
transaction has been recorded, it becomes read only. In the event of an error, a correcting
transaction is entered at a later date. The company wants to maintain only the current
months data in the online database and to archive the remainder to read-only media.
Government regulations require that the company maintain the previous seven years worth
of records of all ATM transactions and that the data be available within 24 hours.
Multiple Choice
Circle the letter or letters that correspond to the best answer or answers.
Use the information in the previous case study to answer the following questions:
1. Fill in the following table (you may need to modify it) to show the online and archived
data-accessibility requirements. Create time divisions, and classify the data based on
those divisions. Ensure that the data classification meets the query requirements.
D ATA S OURCE
A CCESSIBILITY R EQUIREMENT
S TORAGE F ORMAT
Online
Archived
Offline
D ATA M OVEMENT
FREQUENCY
5. If the requirements for the case study were to 1) maintain 36 months of data online
for immediate access for queries and updates and 2) maintain a total of 7 years of data
to meet accounting and reporting requirements, which of the following is the most
appropriate storage format plan?
a. Place the current 36 months worth of data on an OLTP database server and the
previous 4 years worth of data on an archive server.
b. Place all the data on the OLTP server, and use partitioning to separate the data
between the current 36 months and the remaining 48 months.
c. Place the current 36 months of data on an OLTP server and the remainder on tape.
d. Use summary tables to reduce the load on the OLTP server, and store all detailed
data on an archive server.
6. The data-movement strategy should contain which of the following steps? (Choose all
that apply.)
a. Verification that data has been copied to the destination storage format
b. Means to ensure the security of data during movement
c. Specification of the frequency of data movement
d. Scheduling of data movement to minimize impact on the production server
7. Which of the following roles can a single server have in a replication topology?
a. Distributor
b. Publisher
c. Subscriber
8. Enhancements to SQL Server 2005 that simplify administration of a replication
topology include which of the following? (Choose all that apply.)
a. Schema changes can be automatically sent to subscribers without using special stored
procedures.
b. Specific tables of a database can be replicated, not necessarily the whole database.
c. A number of wizards in Management Studio make it much simpler to set up the
replication topology, once its designed.
d. All of the above.
9. You are a database administrator for a small company in Tasmania. You maintain a
Sales database that contains a SalesTransactions table. Requirement are that 36 months
of this table data must be stored online in the Sales database and that older data must
be sent to an archive database. Which of the following is the best way to structure the
SalesTransactions table?
a. Partitioned view
b. Table partitioning
c. Denormalization
d. Summary tables
10. Refer to the previous question. Which archival frequency would you use?
a. Daily
b. Monthly
c. Quarterly
d. Annually
Glossary
285
286 | Glossary
the rows of a table, based on key values.
Indexes can also enforce uniqueness on
the rows in a table. SQL Server supports
clustered and nonclustered indexes. The
primary key of a table is automatically
indexed. In full-text search, a full-text
index stores information about signicant
words and their location within a given
column.
instance: A separate and isolated copy of
SQL Server running on a server. Application service providers can support multiple businesses and their database needs
while guaranteeing one business cannot
see the others data.
log shipping: A technology for high availability that is based on the normal
backup and restore procedures that exist
with SQL Server. In this environment,
transaction-log backups are made on the
principal server and then copied to the
secondary server.
media: The physical item used to store data.
Tapes are a common form of media as
are individual optical storage items such
as CDs and DVDs. The type of media
used must match the physical hardware
device used for reading from and writing
to the media. As an example, an AIT tape
cartridge (the media) must only be used in
an AIT type tape drive.
media retention: A period of time such as
a year, a month, or a week for which any
backup media is not altered and kept
in that state in which it was created.
After this retention period the media is
allowed to be reused for another new
backup.
merge replication: A method of replication
which transfers data from one database to
one or more other databases. Data can be
changed in more than one location. This
may cause conicts to arise.
method: A specic means of action to accomplish a stipulated goal or objective.
mirror database: The passive or secondary
database in a mirroring conguration.
Also known as the secondary database.
object: An object is an allocated region of
storage; an object is named; if the database
structure has a name, its an object. Examples include database, table, attribute,
index, view, stored procedure, trigger, and
so on.
organizational unit: An object within Active
Directory that may contain other objects
such as other organizational Units (OUs),
users, groups, and computers.
Index
% disk time, 69
@loopback_detection, 229
64bit, 2223, 76
A
Access
auditing, 101102
categories, dening, 134
direct, 202
indirect through stored procedures, 202
indirect through views, 202
standards, 201203
Active/active three-node cluster, 217
Active Directory (AD)
as authentication mechanism, 9394
dened, 87, 89
Active/passive two-node cluster, 216
Address Windowing Extensions (AWE), 22
ALTER ENDPOINT statement, 142, 143
ALTER INDEX command, 35
ALTER statement, 137, 139, 141
ALTER TABLE command, 35
Antivirus software, 122
Applications
analyzing for consolidation, 6667
authentication roles, 95
domains, 162
migration, 7879
monitoring for consolidation, 6768
roles, 136137
Archive, dened, 265, 266
Archiving data, 265280
accessibility, 269, 271, 272, 280
business requirements, 267268
costs, 266, 269, 271
data-movement strategy, 273
deciding what to archive, 269272
disk space use, 266, 269
historical data, identifying, 269
interval, 269270
maintenance time, 266
merge replication, 277278
performance, 269
query performance, 266
reasons to, 266273
regulatory requirements, 267268
reliability, 272
replication topology, 274280
scenario, 267268
security, 272
shelf life, 271
snapshot replication, 277
storage media and format, 271272
structure of, 270271
B
Backups
antivirus software, 122
business requirements, 252
compression, 35, 42
data, 243246
database categories based on recovery criteria, 252253
devices, 244
differential, 245
documenting, 256
legroup, 246, 251
les storage, designing, 4142
frequency of, 255
full, differential, and transaction log, 250251
287
288 | Index
Backups (continued)
full only, 244, 249250
full with differential, 250
full with transaction log, 250
partial and partial differential, 251
processes, 10
RAID, 41
recovery types, and, 253255
restore strategy, designing, and, 251253
security policy, 255256
storage, offsite, 255256
strategy, 249257
strategy, key steps, 252
transaction log backups, 42, 245246
validation and testing policy, 256257
very large databases (VLDBs), 246
Best practices
infrastructure, 14
password rules, 110
recovery plan, 260261
BitLocker, 256
Budgetary constraints, dened, 1, 5
Bulk log backup, 42
Business continuity plan (BCP), dened, 242, 257
Business requirements
archiving data, 267268
backup strategy, 252
capacity, 56
infrastructure, 56
views, 187188
C
Cache management, on-chip, 22
camelCase, dened, 194, 198
Capacity
analysis, 4
business requirements, 56
changing, 4
CPU, 11
dened, 1, 45
designing for, 613
disk space, 6
disk space, growth rate, 78
disk throughput, 7
estimation period, 7, 11
horizon, 6
memory usage, 1213
network trafc, 910
network requirements, 910
regulatory requirements, 5, 89
sources of, 6
storage requirements, 69
technical requirements, 45
Certicate, dened, 107, 110
Clients
database mirroring, 223
log shipping, 227228
network trafc, 10
Clustering, 77, 98, 214220
conguration, 216218
consolidation, and, 77
costs, 215
Index | 289
costs, 6061, 64
data evaluation, 7475
deciding against, 6364
deciding for, 6063
decisions, initial, 7577
deploying (phase 4), 8283
developing (phase 3), 8082
environment, examination of, 6673
envisioning (phase 1), 5973
geographic, 65
geographical issues, 7172
goals, 6466
guidelines, 65
hardware acquisition, 8081
instance, 65
management, 6162
on-line analytical processing (OLAP), 65
on-line transaction processing (OLTP), 65
physical server, 65
pilot, 81
planning (phase 2), 7380
proof of concept, 81
resources, use of, 6263
return on investment, 62
risk factor, 64
scope creep, 7980
security, 61
service-level agreements, 71
storage, 65
sunk cost factor, 64
team formation, 5960
types, 65
Constraint(s)
budgetary, 1, 5
check, 181
column, 177
default, 181
dened, 168, 170
naming conventions, 197
prex, 196
unique, 181182
using, 180182
Contact list, 257258
CONTROL statement, 141
Convention, dened, 194
Convention, naming. See Naming convention
Conventions and standards. See Database, conventions
and standards
Costs
archiving data, 266, 269, 271
clustering, 215, 216, 220
consolidation, 6061
cooling capacity, 61
database recovery, 252
data loss, 252
electrical, 6061
high availability, 234
return on investment, 62
salaries, 60
security, 9293
soft versus hard, 61
storage, archival, 271
CPU
64-bit versus 32-bit, 2223, 76
afnity mask, 11
architecture, 2223
capacity, 11
clustering, 219220
consolidation, envisioning, 68
counters, 68
estimation period, 11
evaluating, 74
hot add, 2425
hyperthreading, 2223
monitoring for consolidation, 68
multicore, 22
operating system licenses, 11
as single point of failure, 211
sizing, 78
SQL Server editions, 23
types, 11, 2223
usage, 11
CREATE APPLICATION ROLE
command, 136
CREATE ASSEMBLY command, 145, 146
CREATE ENDPOINT command, 137, 143
CREATE INDEX command, 35
CREATE statement, 137, 139
CREATE TABLE command, 35, 36
CREATE USER statement, 132, 137
Cryptology, dened, 107, 111
D
Data archiving. See Archiving
Database, dened, 169
Database, development, location and role,
203204
Database, physical, design
default databases, 50
denormalization, 171172
documentation and diagramming, 172
legroups, 182184
index usage, 184186
information, gathering, 170
normalization, 171
objects, inventory, 171
planning, 170171
schema, documentation, 173
table design, 173182
views, 187189
Database, production, location and role,
203204
Database, system, location, 4950
Database, test, location and role, 203204
Database access
auditing, 101102
direct, 202
indirect through stored procedures, 202
indirect through views, 202
standards, 201203
Database conventions and standards, 194205
naming conventions, 195199. See also Naming conventions
standards, 200205. See also Standards, database
Database Diagram Designer, 173
290 | Index
Database les
groups, 45
location of, 4445
naming, 45
setting up, 44
size, 45
types, 44, 169
Database Maintenance Plan Wizard, 244
Database mirroring
client applications, 223
versus clustering, 220221
conguration, 221224
dened, 210, 220
endpoints, 224
enhancements, 225
hardware, 220
high availability, security, 98
high-availability mode, 222
high-performance mode, 222
high-protection mode, 222
modes, 222223
network trafc, 10
principal database, 221
protection levels, 222223
quorum, 221
reporting options, 235
scope, 221
secondary database, 221
server roles, designing, 221
solution design, 223
testing, 224225
transaction logs, 38
witness server, 221
Database restore. See Restoring databases
Database size, estimating, 3337
capacity, planning for, 34
data compression, 3435
RAID, 3637
sparse columns, 3536
Database standard(s)
access, 201203
dened, 194, 200
deployment process, 203205
security, 205
Transact-SQL coding, 200201
Data center, cooling capacity, 61
Data compression
mirroring, 225
page, 35
row, 35
Data control language (DCL)
commands, 152
dened, 150
Data denition language (DDL), dened, 129,
Data denition language (DDL) triggers, 137139. See also Triggers, DDL
Data les
log, 31, 44, 169
primary, 3132, 44, 169
secondary, 31, 32, 44, 169
Data manipulation language (DML), 129
Data recovery
backing up data, 243246
Index | 291
E
Execution context, dened, 150, 155
Encrypting File System (EFS) 256
Encryption
cell-level, 256
certicates, 112
column-level, 159161
database-level, 140141, 256
deploying, 160161
hierarchy, 111
keys, 114115
keys, choosing, 160
performance issues, 112113
policy, 113, 140141
symmetric and asymmetric keys, 111112
transparent data encryption (TDE), 140141
triggers, 139141
Windows Server level, 111115
Encryption key, dened, 107, 111
Endpoint(s)
database mirroring, 224
default protocol, 141
policies, dening, 143144
service broker and database mirroring endpoints, 143
SOAP/Web Service endpoints, 142143
TDS endpoints, 142
Entity integrity, 171, 180181
Envisioning, consolidation, 5973
applications, 6668
costs, 6061
CPU, 68
deciding against, 6364
deciding for, 6063
dened, 58, 59
disk performance, 6970
environment, examination of, 6673
geographical issues, 7172
goals, 6466
guidelines, 65
issues, 71, 73
management, centralized, 6162
memory, 6869
resources, use of, 6263
return on investment, 62
security, 61
service-level agreements, 71
SQL Server-specic metrics, 7071
systems, associated, 7273
team formation, 5960
EXECUTE AS CALLER, 155
EXECUTE AS OWNER, 156
EXECUTE AS SELF, 156
EXECUTE AS <user_name>, 155
Execution context, specifying, 155159
auditing, 158159
EXECUTE AS, implementing for an object, 155156
EXECUTE AS, implementing in batches, 157158
EXECUTE AS policy, batches, developing, 159
EXECUTE AS policy, objects, developing, 156
NO REVERT, 157
NO REVERT COOKIE, 158
scope of the EXECUTE AS statements, 157
F
Failover
automatic versus manual, 214
cluster, 215
database mirroring, 222223
dened, 210, 212, 213
delay, 221
planned, 224225
three-node, 217
unplanned, 225
Fault tolerance, designing, 233
Filegroup (s)
backups, 251
dened, 30, 32
designing, 182184
partitioning, 184
performance, 183
recoverability, 184
setting up, 45
Filenames, setting up, 45
File size, setting up, 45
Firewall, 124125
Five nines, 211
Format, dened, 265
Full backups, 244, 249251
Full-Text Search, 73
G
Geographic consolidation, 65
Global Allocation Map (GAM), 31, 33
GRANT statement, 136, 141
H
Hard disk, speed versus memory speed, 32
Hardware
acquiring, 8081
clustering, 215, 219220
conguration, 1325
consolidation, 8081
database mirroring, 220
failure, 243
partitioning, 175
sizing, 78
WSC-certied, 215
Hardware Security Module (HSM), 114
High Availability (HA)
backups, protecting, 101
clustering, 214220
consolidation, planning, 7677
costs, 234
database mirroring, 213, 220225
dened, 210, 214
dynamic name system (DNS), 237
failover, 212213
goals, 212213
292 | Index
High Availability (HA) (continued)
HTTP attacks, guarding against, 100
limitations, 213214
log shipping, 213, 226228
migration strategy, 235237
password cracking, 100101
replication, 213, 228230
for reporting purposes, 235
server attacks, 99
single points of failure, 211212
solution design, 233235
source code, managing, 100
SQL injection attacks, 100
stafng, 234235
storage, 230233
technologies, 211214
training costs, 77
Horizon, dened, 1, 6
Horizontal partitioning, 175
HTTP requests, responding to, 142
Human malevolence, 244
Hyperthreading, 2223
I
Impersonation and delegation, 9596
Index Allocation Map (IAM), 31, 33
Indexed Sequential Access Method (ISAM), 31
Index(es)
access speed, 185186
clustered, 184185
Database Tuning Advisor, 186
dened, 169
designing, 184186
naming conventions, 197
nonclustered, 184185
placement, physical, 186
Infrastructure, database server
designing, 125
capacity requirements, 613
conguration, current, analyzing, 26
software versions and hardware congurations, 1325
Instance(s)
assigning ports to, 53
clustering, 47
congurations, specifying, 5253
consolidation, 65, 76
default, 4546
dened, 30
designing, 4546
named, 46, 97
naming conventions, 4748
number of, 4647
service requirements, establishing, 52
system databases, location of, 4950
Integrity, data, 171
K
Kerberos
as authentication method, 9495
endpoints, using, 142
Keys, encryption
asymmetric, 107, 111112
L
.ldf le extension, 44
Local service account, 117, 118
Local system account, 117, 119
Logins
creating, 130131
system adminstrator (sa), 130
Log shipping
advantages and disadvantages, 226
antivirus software, and, 122
client applications, reconnecting, 227228
conguration, 226227
dened, 210, 226
high availability, 226228
reporting options, 235
roles, choosing, 226227
roles, switching, 227
security, 98
transaction log, 38
M
.mdf le extension, 44
Media, dened, 265
Media and format, storage, 271272
Media retention, dened, 242, 255
Memory
analyzing, 1213
consolidation, envisioning, 6869
consolidation, planning, 7475
direct addressable, 22
evaluating, 7475
forecasting and planning for, 13
growth rate, 13
monitoring, for consolidation, 6869
options, choosing, 2324
sizing, 78
speed versus hard disk speed, 32
System Monitor counters, 12
usage, assessing, 1213
Memory: Available Bytes, 12, 68
Memory: Pages/sec, 12
Memory: Paging File: % Usage, 68
Merge replication
archiving data, 277278
dened, 210, 229
high availability, 230
Method, dened, 194, 204
Microsoft Cluster Services (MSCS), 214
Microsoft Operations Manager (MOM), 13
Microsoft Solutions Framework (MSF), phases, 5859
Migration
address abstraction, implementing, 237
Index | 293
consolidation, application, 7879
domain issues, 79
downtime, minimizing, 236
of DTS packages to Integration
Services, 79
high availability, 235237
logins, 78
security issues, 79
testing, 236
training, 237
users, 78
Mirror database, dened, 210, 221
Mirroring, 36, 231. See also Database mirroring
Mitigation plan, 257261
business continuity plan, 257
contact list, 257258
database loss scenarios, 259
decision tree, 258259
disaster recovery plan, 257
documentation, 258
information, categorizing, 257
recovery decision tree, 260
recovery plan best practices, 260261
recovery steps priorities, 259260
recovery success criteria, 258
msdb, 70
Multicore CPU, 22
Multiple Active Result Sets (MARS), 51
N
Naming conventions
arguments against, 196
bad practices, 198199
benets of, 195196
for database objects, 196197
documenting and communicating, 199
establishing and disseminating, 196199
instances, 4748
pitfalls, avoiding, 198199
vendors, 199
.ndf le extension, 44
.NET Assembly security, designing, 145146
EXTERNAL_ACCESS, assemblies,
setting, 146
SAFE assemblies, setting, 145146
UNSAFE assemblies, setting, 146
Network diagrams, 9
Network policies, 9697
Network service account, 117, 119
Network trafc
analyzing, 910
bottlenecks, 10
between clients and servers, 10
forecasting and planning for, 10
identifying, 9
between servers, 10
NORECOVERY option, 247248
Normalization
database, 171
tables, 175
NO_TRUNCATE option, 247, 250
NTFS le system, 44
O
Object(s)
dened, 169
EXECUTE AS, 155156
naming conventions, 196197
permission, 154
as a security level, 89
Object-level security, 150164
common language runtime (CLR),
161164
encryption, column level, 159161
execution context, specifying, 155159
permissions, existing, analyzing, 154155
permissions, strategy, developing, 151153
On-line analytical processing (OLAP), 65
On-line transaction processing (OLTP), 65
Operating system
CPU licensing, 11
installation location, 43
version and edition, choosing, 1420
Organizational unit, dened (OU), 87
Orphaned users, 132
P
Page, dened, 30, 32
Page Free Space, 31, 33
Pages, 3233
Parallelism, on-processor, 22
Partitioning, tables, 174175
PascalCase, dened, 194, 198
Password
best practices, 110
change, enforced at next login, 110
cracking, 100101
expiration, enforced, 109
options, 108109
policy, 109
Performance
archiving data, 269
consolidation, 6263, 6970
database mirroring, 222
disk, monitoring, 6970
encryption, 112113
legroup, 183
query, 266
tempdb, 63
Permission(s)
ALTER, 151, 153
CREATE, 151, 153
Data Control Language (DCL) commands, 152
dened, 150, 151
DENY, 151, 152, 155
DROP, 151
existing, analyzing, 154155
GRANT, 152, 154
list of, 152154
object, 154
REVOKE, 152, 155
roles, 151
specic, applying, 153
strategy, developing, 151153
VIEW DEFINITION, 154
294 | Index
Planning, consolidation, 7380
application migration, 7879
clustering, 77
data evaluation, 7477
decisions, initial, 7576
dened, 58, 73
disk subsystem, 75
hardware, sizing, 78
high availability, 7677
instances, multiple, choosing, 76
iterations, multiple, going through, 77
memory data evaluation, 7475
processor data evaluation, 74
scope creep, 7980
64-bit SQL Server, 76
upgrade advisor, 76
Policies
dened, 1, 5
encryption, 113, 140141
endpoint, 143144
EXECUTE AS, for batches, 159
EXECUTE AS, for objects, 156
network, authentication, 9697
password rules, 109
security, backup strategy, 255256
security, common language runtime, 163164
security, dened, 87, 88
security, encryption, 140141
triggers, DLL, dening, 139
validation and testing, backup strategy,
256257
Primary key, choosing, 176
Principle database, dened, 210, 221
Principle server, dened, 210, 212
Process: Private Bytes: sqlservr process, 68
Process: SQ: Server process: % Processor Time, 68
Process: Working Set, 12
Processor: % Processor Time, 68
Production data, protecting during deployment, 204
Production database,
data integrity, 204
role and location of, 203204
Proxies, 144145
Pure log backup, 42
Q
Quorum
dened, 210, 221
drives, 122
R
RAID
0, 3637, 231
1, 3637, 231
5, 37, 231232
10, 37, 232
backups, 41
database size, 3637
designing, 232
disk performance, monitoring, 69
levels, choosing, 223
transaction log les, 40
Index | 295
S
SAN storage, 75, 232233
Schema(s)
dbo, 134
dened, 129, 133
naming conventions, 197
naming structure, 133
securing, 133134
as a security level, 89
Scope, dened, 129
Scope creep, 7980
Secondary database, dened, 210, 221
Secure Socket Layer (SSL). See SSL
Security
administrative, 95
analyzing and designing, 87106
antivirus software, 122
application domains, 162
application roles, 95
archiving data, 272
assemblies, creating, 161
assemblies, trusted, 162
auditing access, 101102
authentication, 9397
backups, protecting, 101
benets, 93
CLR, 161164
conicts, 9192
costs, 9293
database level, 8991, 135137, 140141
DDL triggers, 137139
encryption, column level, 159161
encryption, policy, 110115, 140141
endpoints, securing, 141144
execution context, specifying, 155159
rewalls, 96, 124125
high availability, 97101
HTTP attacks, 100
impersonation and delegation, 9596
levels, 8991
logins, creating, 130131
module signing, 162163
.NET assembly, 145146
object-level, 150164
password cracking, 100
password rules, 108110
permissions, existing, analyzing, 154155
permissions strategy, developing, 151153
policies, 99, 163164
recommendations, making, 102
requirements, gathering, 8893
resources, external, accessing, 162163
reviews, performing, 102
risk factors, 93
roles, database, granting, 134137
roles, server, granting, 131132
roles, SQL Server Agent, job, 144145
schema level, 8991
schemas, securing, 133134
scope, 8990
server level, 8991, 129134
service level, 8991
296 | Index
SQL Server 2005 (continued)
hard disk space requirements, 24
instances per edition and component, 47
services, list of, 43
storage requirements, 24
SQL Server 2008
backup compression, 42
choosing, 2122
clustering enhancements, 218219
CPU type and speed, 23
data compression, 3435, 43
datatypes, table, 180
editions, 1620, 2122, 23, 24
Extensible Key Management, 114115
hard disk space requirements, 24
hot add CPUs and RAM, 2425
instances, 48
mirroring enhancements, 225
RAM, 24
sparse columns, 3536
software modules, disk space, 24
storage requirements, 24
transparent data encryption (TDE),
140141, 256
SQL Server Authentication, 9394, 108
SQL Server: Buffer Manager, 12
SQL Server: Buffer Manager: Buffer Cache Hit Ratio, 68
SQL Server: Buffer Manager: Stolen Pages and Reserved
Pages, 68
SQL Server: Buffer Manager: Page Life Expectancy, 12
SQL Server: Cache Manager: Cache Hit Ratio, 70
SQL Server: Databases: Database Size: tempdb, 70
SQL Server: Databases: Transactions/sec, 70
SQL Server: General Statistics: User Connections, 70
SQL Server hierarchy, 90
SQL Server Integration Services (SSIS), 97
SQL Server: Memory Manager: Total Server Memory,
12, 68
SQL Server metrics, monitoring, 7071
SQL Server Service Executables, location of, 4344
SQL Server Services
dened, 107, 115116
list of, 3, 43, 116117
modes, 123124
TCP port numbers, 124
working with, 123124
SSL encrypted connections, 97
Staff
consolidation, 83
contact list, 257258
deployment process, 204
disaster situations, 234235
high availability, 234235
training, 237
Standard(s), database
access, 201203
dened, 194, 200
deployment process, 203205
security, 205
Transact-SQL coding, 200201
Storage, archival
accessibility, 271, 272
costs, 271
data movement strategy, 273
media type and format, 271273
reliability, 272
security, 272
shelf life, 271
technology, changing, 272
Storage, high availability, 230233
fault tolerance, 233
RAID arrays, 231232, 233
SAN storage array, 232233
Storage, media and format, 271272
Storage, physical, 3057
backup-le storage, 4143
concepts, 3133
database size, 3337
data compression, 3435
data les, 3132
extents, 33
le placement, 4445
le types, 3132
instances, 4548
operating system, location of, 43
pages, 3233
planning for, 34
RAID, 3637
servers, number needed, 4950
sparse columns, 3536
tempdb database, 5053
transaction logs, 3132, 3741
SQL Server Service Executables, 4344
Storage capacity
analyzing, 69
disk space, 67
disk throughput, 7
locations and roles of database servers, 7
requirements, determining, 24
Storage consolidation, 65
Stored procedures
database access, indirect, 202
execute permission, 153
extended (XPs), 73
naming conventions, 196, 197198
sp_change_users_login, 132
sp_congure, 4
sp_estimate_data_compression_savings, 35
sp_ prex, 198
sp_unsetapprole, 137
usp_ prex, 198
Striping, 36, 231
Striping with parity, 37, 231232
Sunk cost factor, 64
Surface Area Conguration Manager, 73
Symmetric key
algorithms, 111
dened, 107
sys.dm_exec_cached_plans, 12
sys.dm_exec_query_stats, 12
sys.dm_os_memory_clerks, 12
sys.dm_os_memory_objects, 12
System Center Operations Manager (SCOM), 13
System Monitor counters, 12
Index | 297
T
Table(s)
for archiving, 270
computed columns, 182
constraints, 180182
datatypes, built-in SQL Server, 177180
datatypes, column, 177
datatypes, user-dened, 180
dened, 169, 173
denormalized, 270
design, 173182
integrity, 180181
keys, foreign, 176177
keys, primary, 176
keys, specifying, 175
location, physical, 182
naming conventions, 197
normalized, 175, 270
partitioned, 270
partitioning, 174175
row splitting, 175
summary, 270
Tail log backup, 42
TAKE OWNERSHIP statement, 141
TCP ports, 53, 124
Technical requirements, capacity, 45
tempdb
Conguration Manager, 5253
disk performance, 70
instance congurations, 5253
services, 52
size, 5152, 76
usage, 76
Test database, role and location of, 203204
Topology, dened, 265
Transactional replication
@loopback_detection, 229
archiving data, 276277
dened, 210
high availability, 229230
Transaction log(s),
adding or enlarging, 40
backups, 42, 245246, 250251
database mirroring, 38
data recovery, 3839
designing, 3738
FILEGROWTH setting, 39
les, 31, 32
le size, managing, 3841
log shipping, 38
RAID, 40
recoverability, 32
recovery, 39
replication, 38
shrinking, 40
U
Upgrade Advisor, 76
User-dened functions, naming conventions, 197
User-dened integrity, 171
V
Vertical partitioning, 175
VIEW DEFINITION, 141, 154
View(s)
backward compatibility, 188
business requirements, 187188
database access, indirect, 202203
data customization, 188
data import/export, 188
data manipulation, 188
dened, 169, 187
designing, 187189
dynamic management, 12
ltering, row and column, 189
indexed, 188
naming conventions, 197
partitioned, 188189
standard, 188
types, 188189
user data, 188
W
Windows authentication, 9394, 108
Windows Server Catalog (WSC), 215
Windows server-level security, 107128
antivirus software, 122
asymmetric keys, 112
certicates, 112
encryption policy, 110115
rewalls, server, 124125
password rules, 108110
services, working with, 123124
SQL Server service accounts, 115121
symmetric keys, 111
Witness server, dened, 210, 221
Write-ahead log, 32, 37