Table of Contents

Copyright

Brief Table of Contents

Table of Contents

List of Figures

List of Tables

List of Listings

MVP contributors and their chapters

Preface

Acknowledgments

About War Child

About this Book

About SQL Server MVPs

1. Database design and architecture

Chapter 1. Louis and Paul’s 10 key relational database design ideas

1. Denormalization is for wimps

2. Keys are key

3. Generalize, man!

4. Class <> table

5. Data drives design

6. Sets good, cursors bad

7. Properly type data

8. Extensibility through encapsulation

9. Spaghetti is food, not code

10. NOLOCK = no consistency

Summary

About the authors

Chapter 2. SQL Server tools for maintaining data integrity

Protection tools

Data types

NULL specification

Uniqueness constraints

Filtered unique indexes

Foreign key constraints

Check constraints

Triggers

When and why to use what tool

Summary

About the author

Chapter 3. Finding functional dependencies

Interview method

Modeling the sales order

First step: finding single-attribute dependencies

Second step: finding two-attribute dependencies

Further steps: three-and-more-attribute dependencies

What if I have some independent attributes left?

Summary

About the author

2. Database Development

Chapter 4. Set-based iteration, the third alternative

The common methods and their shortcomings

Declarative (set-based) code

Iterative (cursor-based) code

Set-based iteration

The most basic form

Running totals

Bin packing

Summary

About the author

Chapter 5. Gaps and islands

Description of gaps and islands problems

Sample data and desired results

Solutions to gaps problem

Gaps—solution 1 using subqueries

Gaps—solution 2 using subqueries

Gaps—solution 3 using ranking functions

Gaps—solution 4 using cursors

Performance summary for gaps solutions

Solutions to islands problem

Islands—solution 1 using subqueries and ranking calculations

Islands—solution 2 using group identifier based on subqueries

Islands—solution 3 using group identifier based on ranking calculations

Islands—solution 4 using cursors

Variation on the islands problem

Performance summary for islands solutions

Summary

About the author

Chapter 6. Error handling in SQL Server and applications

Handling errors inside SQL Server

Returning information about the error

Generate your own errors using RAISERROR

Nesting TRY...CATCH blocks

TRY...CATCH and transactions

Handling SQL Server errors on the client

Handling SQL Server messages on the client

Summary

About the author

Chapter 7. Pulling apart the FROM clause

JOIN basics

The INNER JOIN

The OUTER JOIN

The CROSS JOIN

Formatting your FROM clause

A sample query

The appearance of most queries

When the pattern doesn’t apply

How to read a FROM clause

When the pattern can’t apply

Writing the FROM clause clearly the first time

Filtering with the ON clause

The different filters of the SELECT statement

Filtering out the matches

JOIN uses and simplification

The four uses of JOINs

Simplification using views

How JOIN uses affect you

Summary

About the author

Chapter 8. What makes a bulk insert a minimally logged operation?

Recovery and locking

Creating the file to import

Creating the tables to store the data

Importing the data

Summary

About the author

Chapter 9. Avoiding three common query mistakes

NULL comparisons

Multiple OUTER JOINS

Incorrect GROUP BY clauses

Summary

About the author

Chapter 10. Introduction to XQuery on SQL Server

What is XQuery?

How XQuery sees your XML

Querying XML

FLWOR expressions

XQuery comparison operators

XML indexes and XQuery performance

Summary

About the author

Chapter 11. SQL Server XML frequently asked questions

XML basics

What’s XML?

What’s “well-formed” XML?

What’s the prolog?

What’s an entity?

What’s a DTD?

The xml data type

Why does SQL Server remove the DTD from my XML data?

How do I preserve whitespace in my XML?

Why am I getting strange characters in my XML?

How do I query XML data?

How do I query a single value from my XML data?

How do I shred XML data?

Advanced query topics

How do I specify an XML namespace in my XQuery queries?

How do I get all element names and values from my XML document?

How do I load XML documents from the filesystem?

Summary

About the author

Chapter 12. Using XML to transport relational data

Understanding before coding

The concept

The logical model

The physical model

The database

The XML Schema

Enabling and maintaining the data flow

Preparing the inbound data flow

Importing the data

Exporting the data

Preparing the sample data

Homework

Summary

About the author

Chapter 13. Full-text searching

Foundations of full-text searching

Creating and maintaining catalogs

Creating and maintaining full-text indexes

Creating the full-text index

Maintaining full-text indexes

Querying full-text indexes

Basic searches

FORMSOF

Phrases, NEAR, OR, and prefixed terms

Ranking

Custom thesaurus and stopwords

Custom thesaurus

Stopwords and stoplists

Useful system queries

Basic queries to discover what catalogs, indexes, and columns exist

Advanced queries

The keywords

Summary

About the author

Chapter 14. Simil: an algorithm to look for similar strings

Equals (=) and LIKE

SOUNDEX and DIFFERENCE

CONTAINS and FREETEXT

Simil

Algorithm

Implementation in .NET

Installation

Usage

Testing

Summary

About the author

Chapter 15. LINQ to SQL and ADO.NET Entity Framework

LINQ to SQL and performance

Generating SQL that uses projection

Updating in the middle tier

Optimizing the number of database round trips

LINQ to SQL and stored procedures

Tuning and LINQ to SQL queries

Summary

About the author

Chapter 16. Table-valued parameters

What’s the problem?

Table-valued parameters to the rescue!

Another TVP example

Using TVPs from client applications

Using a DataTable

Using a DbDataReader

Using TVPs to enter orders

Summary

About the author

Chapter 17. Build your own index

The database and the table

Plain search and introducing tester_sp

Using the LIKE operator—an important observation

Using a binary collation

Fragments and persons

The fragments_persons table

Writing the search procedure

Keeping the index and the statistics updated

What is the overhead?

Fragments and lists

Building the lists

Unwrapping the lists

The fragments_personlists table

Loading the table

A search procedure

Keeping the lists updated

Using bitmasks

The initial setup

Searching with the bitmask

Adapting the bitmask to the data

Performance and overhead

The big bitmask

Summary

About the author

Chapter 18. Getting and staying connected—or not

What is SQL Server?

Understanding the SQL Server Browser service

Diagnosing a connectivity problem

Testing for network availability

Managing the SQL Server instance state

Finding visible SQL Server instances

What is a connection?

To connect or not to connect...

Connection management

Connection strategies

Establishing a connection

The server key

Trusted or untrusted security?

Using trusted or integrated security

ASP.NET considerations

Using SQL Server authentication

Accepting user login credentials—or not

Accessing user instances

Connection pooling

Closing the connection

Summary

About the author

Chapter 19. Extending your productivity in SSMS and Query Analyzer

Custom keyboard shortcuts

Creating your custom utility to use with keyboard shortcuts

Some ideas for utilities to implement

Summary

About the author

Chapter 20. Why every SQL developer needs a tools database

What belongs in the tools database?

Creating the tools database

Using an auxiliary table of numbers

Generating a calendar on the fly

Splitting strings with a numbers table

Placing common code in the tools database

Formatting

Calling code from a different database

Summary

About the author

Chapter 21. Deprecation feature

A simple usage example

Methods of tracking deprecated features

Summary

About the author

Chapter 22. Placing SQL Server in your pocket

Design goals

Architecture

Deployment

Deploying on a desktop

Deploying on a device

XCOPY deployment

Tool support

Programming support

Summary

About the author

Chapter 23. Mobile data strategies

Microsoft Sync Framework (MSF)

Client synchronization provider

Server synchronization provider

Synchronization adapter

Synchronization agent

Using MSF

Comparison

Summary

About the author

3. Database Administration

Chapter 24. What does it mean to be a DBA?

Typical DBA tasks: A to Z

Application Integration

Archiving Data

Attending Meetings

Auditing

Backup and Recovery

Business Intelligence and Data Warehousing

Capacity Planning

Change Management

Data Modeling and Database Design

Database Application Development

Developing and Maintaining Best Practices

Disaster Recovery

Hardware Setup and Configuration

High Availability

Installing, Configuring, and Upgrading SQL Server Software

Load Balancing

Maintaining Documentation

Managing People

Managing SQL Server–Based Applications

Managing Test Environments

Mentoring

Monitoring

Needs and Requirements Analysis

Negotiating Service Level Agreements

Operating System Setup, Configuration, and Administration

Performance Tuning

Project Management

Replication

Report Writing

Running Jobs

Scripting

Security

SSIS and ETL

Testing

Troubleshooting

Working with Teammates

DBA specialties

DBA System Administrator

DBA Database Architect

DBA Database Designer

DBA Developer

DBA High Availability and Disaster Recovery Specialist

DBA Business Intelligence Specialist

DBA Report Writer

Summary

About the author

Chapter 25. Working with maintenance plans

What is a maintenance plan, and how do I create one?

Versions and service packs

One or several schedules per plan?

Wizard dialogs

Task types

Check database integrity task

Shrink database task

Reorganize index task

Rebuild index task

Update statistics task

History cleanup task

Execute SQL Server Agent job task

Back up database task

Maintenance cleanup task

Select reporting options

Execute T-SQL statement task

Executing and monitoring the plan

Summary

About the author

Chapter 26. PowerShell in SQL Server

PowerShell overview

PowerShell features

PowerShell issues and solutions

PowerShell with SQL Server 2000 and 2005

Data access

Administration

PowerShell with SQL Server 2008

SQLPS

Provider

Cmdlets

Summary

About the author

Chapter 27. Automating SQL Server Management using SMO

Loading required libraries

Backup

Restore

Creating a database

Scripting

Summary

About the author

Chapter 28. Practical auditing in SQL Server 2008

Overview of audit infrastructure

Server audit objects

Server audit specification objects

Database audit specification objects

Server audits

Configuring the Windows Security Log target

Creating a server audit using the Windows Security Log target

Creating a security audit using the Windows Application Log target

Configuring a server audit using the File target

Server audit specifications

Creating server audit specifications

Viewing audit events

Database audit specifications

Creating database audit specifications

Summary

About the author

Chapter 29. My favorite DMVs, and why

What is so great about DMVs, anyway?

A brief list of my favorite DMVs and DMFs

sys.dm_os_sys_info

sys.dm_exec_sessions, sys.dm_exec_requests, and sys.dm_exec_connections

sys.dm_exec_sql_text

sys.dm_exec_query_stats

sys.dm_exec_procedure_stats

sys.dm_db_index_usage_stats

sys.dm_db_missing_index_details, sys.dm_db_missing_index_groups, and sys.dm_db_missing_index_group_stats

Honorable mentions

sys.dm_os_performance_counters

sys.dm_db_partition_stats

sys.dm_db_index_physical_stats

sys.dm_sql_referenced_entities

Setting up a utility database

Some interesting applications of my favorite DMVs

A more refined sp_who or sp_who2

Getting statistics for stored procedures (SQL Server 2008 only)

Finding unused stored procedures (SQL Server 2008 only)

Finding inefficient and unused indexes

Finding inefficient queries

Finding missing indexes

DMV categories in SQL Server

Summary

About the author

Chapter 30. Reusing space in a table

Understanding how SQL Server automatically reuses table space

Recognizing when SQL Server does not reclaim space

Using DBCC CLEANTABLE to reclaim unused table space

Summary

About the author

Chapter 31. Some practical issues in table partitioning

Table partitioning dependencies

Manipulating partitioned data

How the partition function works

Drilling down: using SPLIT and MERGE

Drilling down: using SWITCH

The key: avoiding data movement

Sources for more information

Summary

About the author

Chapter 32. Partitioning for manageability (and maybe performance)

Overview

How to partition

Planning and design considerations

Gotchas and tips

Boundary time values

SPLIT and MERGE performance

Update statistics after SWITCH

Shared partition functions and schemes

Summary

About the author

Chapter 33. Efficient backups without indexes

It’s OK to not back up nonclustered indexes!

A simple example

Default table and index storage behavior

Adding a dedicated filegroup for nonclustered indexes

Moving nonclustered indexes into the new filegroup

Backing up only the PRIMARY filegroup

Restoring the PRIMARY filegroup backup

Restoring for extraction only

Restoring for production use

Restoring for production use—step by step

usp_Manage_NCIX_Filegroup

Planning before moving NCIXs into a dedicated filegroup

Moving NCIXs temporarily requires additional disk space

Moving NCIXs creates empty space in PRIMARY filegroup

Log shipping

Summary

About the author

Chapter 34. Using database mirroring to become a superhero!

Why should I use database mirroring?

How does database mirroring work?

How do you set up database mirroring?

How do you prepare the mirror?

Using database mirroring for routine maintenance

Using database mirroring to upgrade to SQL Server 2008

Using database mirroring to move data seamlessly

Case study of moving data with database mirroring

Lessons learned from case study

Summary

About the author

Chapter 35. The poor man’s SQL Server log shipping

Creating the T-SQL script

Creating a cleanup script

Creating a batch file

Improving the log shipping process

Summary

About the author

Chapter 36. Understated changes in SQL Server 2005 replication

Undocumented or partially documented changes in behavior

Reading the text of hidden replication stored procedures

Creating snapshots without any data—only the schema

Some changed replication defaults

More efficient methodologies

Remove redundant pre-snapshot and post-snapshot scripts

Replace merge -EXCHANGETYPE parameters

Summary

About the author

Chapter 37. High-performance transactional replication

Performance kiss of death factors in transactional replication

Batch updates

Replicating text

Logging

Network latency

Subscriber hardware

Subscriber indexes and triggers

Distributor hardware

Large numbers of push subscriptions

Optimal settings for replication

CommitBatchSize and CommitBatchThreshold

Update proc

SubscriptionStreams

Summary

About the author

Chapter 38. Successfully implementing Kerberos delegation

Understanding the issues that Kerberos delegation resolves

The double hop

A generic infrastructure—our business challenge

Understanding Kerberos delegation

Service principle names

Constrained delegation

Implementing Kerberos delegation step by step

Configuring the Active Directory

Configuring the client tier

Configuring the web tier

Configuring the data tier

Validating delegation from end to end

Downloading and installing DelegConfig

Running DelegConfig from the web tier

Running DelegConfig from the client tier

Resources to assist in more complex infrastructures

Summary

About the author

Chapter 39. Running SQL Server on Hyper-V

Virtualization architecture

Benefits of isolation

Configuring virtual machines

Configuring disks

CPU configuration

Configuring networking

Memory configuration

Addressing clock drift issues

Backup considerations

Advantages of physical to virtual migration

Test environments and virtualization

Summary

About the author

4. Performance Tuning and Optimization

Chapter 40. When is an unused index not an unused index?

Overview of indexing

Unused indexes

Unused indexes that are actually used

How is the unused index being used?

How does this affect me?

Summary

About the author

Chapter 41. Speeding up your queries with index covering

Index covering speeds up selects

Some rules of thumb about indexes aren’t true for covering indexes

Covering indexes usually slow down modifications

One index should cover many queries

One index can both cover queries and implement uniqueness

Summary

About the author

Chapter 42. Tracing the deadlock

What’s a deadlock?

Causes of deadlocks

Deadlock graph

Trace flag 1204

Trace flag 1222

SQL Profiler

Reading the deadlock graph

The process list

The resource list

The big picture

Summary

About the author

Chapter 43. How to optimize tempdb performance

What is tempdb used for?

Tempdb internals

How DBAs can help optimize tempdb

Minimizing the use of tempdb

Preallocating tempdb space and avoiding use of autogrowth

Don’t shrink tempdb if you don’t need to

Dividing tempdb among multiple physical files

Moving tempdb to a disk separate from your other databases

Locating tempdb on a fast I/O subsystem

Adding RAM to your SQL server instance

Using SQL Server 2008 transparent data encryption

Leaving auto create statistics and auto update statistics on

Verifying CHECKSUM for SQL Server 2008

Summary

About the author

Chapter 44. Does the order of columns in an index matter?

Understanding the basics of composite indexes

Finding a specific row

Finding a last name

Finding a first name

Summary

About the author

Chapter 45. Correlating SQL Profiler with PerfMon

What vexes you?

Getting started with PerfMon and Profiler

Best practices using PerfMon

Best practices using Profiler

A correlated view of performance

Summary

About the author

Chapter 46. Using correlation to improve query performance

The purpose of the optimizer

Correlation with the clustered index

Low correlation

When the optimizer does it right

When the optimizer does it right again

When the optimizer gets it wrong

Correcting the optimizer

When to expect correlation

Determining correlation

Summary

About the author

Chapter 47. How to use Dynamic Management Views

Why should I use DMV queries?

Setting up security to run DMV queries

Looking at top waits at the instance level

Looking for CPU pressure and what’s causing it

Finding I/O pressure in SQL Server

SQL Server memory pressure

SQL Server index usage

Detecting blocking in SQL Server

Summary

About the author

Chapter 48. Query performance and disk I/O counters

Expensive I/Os and very expensive I/Os

Disk performance counters

Random or sequential I/Os and disk performance counters

SQL Server operations and I/O sizes

How expensive are small random I/Os, anyway?

Performance scenarios

Scenario 1: constant checkpoints

Scenario 2: NOLOCK and faster query processing

Scenario 3: read-ahead reads

Scenario 4: index fragmentation

Summary

About the author

Chapter 49. XEVENT: the next event infrastructure

Extended Events infrastructure characteristics

XEVENT architecture

SQL Server Extended Events engine

Packages

Events

Targets

Actions

Predicates

Types and maps

Sessions

XEVENT in action

Usage scenarios

System health session

Performance considerations

Summary

About the author

5. Business intelligence

Chapter 50. BI for the relational guy

Business intelligence overview

Terminology

Really, what is so different?

Approach

Dimensional modeling

Cubes, anyone?

Microsoft BI stack

How do I get started?

Summary

About the author

Chapter 51. Unlocking the secrets of SQL Server 2008 Reporting Services

Why should developers care about Reporting Services?

What is Reporting Services?

Using Visual Studio to create an RDL report

Using the Visual Studio 2008 Report Designer

Managing report parameters

Deploying your report

Using the Report Manager

Using the Visual Studio MicrosoftReportViewer control

What’s in Reporting Services 2008 for developers?

Virtual directory changes

Using SQL Server Reporting Services Configuration Manager

Exporting reports

Enabling My Reports

Working with the Report Designer

Summary

About the author

Chapter 52. Reporting Services tips and tricks

Performance tips

Filters versus query parameters

Linked servers

Drillthrough instead of drill-down

Data export

Connection pooling

Design tips

Stored procedures and temp tables

Excel merged cell solution

Excel web queries and reports

HTML or Word documents

Server portability

Embedding T-SQL in a report

User!UserID

Summary

About the author

Chapter 53. SQL Server Audit, change tracking, and change data capture

What are these solutions used for?

What do people do now?

How does SQL Server 2008 solve these problems?

SQL Server Audit

Change tracking

Change data capture

Comparison of features

Summary

About the author

Chapter 54. Introduction to SSAS 2008 data mining

Data mining basics

Data mining projects

Data overview and preparation

SSAS 2008 data mining algorithms

Creating mining models

Harvesting the results

Viewing the models

Evaluating the models

Creating prediction queries

Sources for more information

Summary

About the author

Chapter 55. To aggregate or not to aggregate—is there really a question?

What are aggregations?

Designing aggregations

Influencing aggregations

Attribute relationships

Usage-based optimization

High-level approach

Other considerations

Summary

About the author

Chapter 56. Incorporating data profiling in the ETL process

Why profile data?

Introduction to the Data Profiling task

Types of profiles

Input to the task

Output from the task

Constraints of the Data Profiling task

Making the Data Profiling task dynamic

Changing the database

Altering the profile requests

Setting the ProfileInputXml property

Making data-quality decisions in the ETL

Excluding data based on quality

Adjusting rules dynamically

Consuming the task output

Capturing the output

Using SSIS XML functionality

Using scripts

Incorporating the values in the package

Summary

About the author

Chapter 57. Expressions in SQL Server Integration Services

SSIS packages: a brief review

Expressions: a quick tour

Expressions in the control flow

Expressions and variables

Expressions in the data flow

Expressions and connection managers

Summary

About the author

Chapter 58. SSIS performance tips

SSIS overview

Control flow performance

Data flow performance

Source acquisition performance

Data transformation performance

Destination performance

Lookup transformation performance

General data flow performance

Summary

About the author

Chapter 59. Incremental loads using T-SQL and SSIS

Some definitions

A T-SQL incremental load

Incremental loads in SSIS

Creating the new BIDS project

Defining the lookup transformation

Setting the lookup transformation behavior

Summary

About the author

Index

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset