1. Trang chủ
  2. » Công Nghệ Thông Tin

SQL server MVP Deep dives volume 2

690 3,4K 0

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 690
Dung lượng 16,19 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

In this book, the world’s leading practitioners of SQL Server present a collection of articles on techniques and best practices for SQL Server development and administration based on many years of combined experience. The 53 MVPs who contributed to the book each picked an area of special interest to them and shared their insights and practical knowhow with you. The topics covered will appeal to a broad range of readers with varied levels of SQL Server experience, from beginner to advanced.

Trang 1

Chris Shaw ● Gail Shaw ● Linchi Shea ● Jason Strate ● Paul Turley ● William Vaughn ● Peter Ward ● Joe Webb ● John Welch ● Allen White ● Thiago Zavaschi

Trang 2

SQL Server MVP Deep Dives

Volume 2

Trang 5

For online information and ordering of this and other Manning books, please visit

www.manning.com The publisher offers discounts on this book when ordered in quantity For more information, please contact

Special Sales Department

Manning Publications Co

20 Baldwin Road

PO Box 261

Shelter Island, NY 11964

Email: orders@manning.com

©2012 by Manning Publications Co All rights reserved

No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher

Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks Where those designations appear in the book, and Manning

Publications was aware of a trademark claim, the designations have been printed in initial caps

or all caps

Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine

Development editor: Cynthia Kane

ISBN 9781617290473

Printed in the United States of America

1 2 3 4 5 6 7 8 9 10 – MAL – 16 15 14 13 12 11

Trang 6

To all the children of Operation Smile

Trang 8

Mladen Prajdic´ 28

Abolfazl Radgoudarzi 48 Denis Reznik 29

Rafael Salas 52 Edwin Sarmiento 44 Chris Shaw 3 Gail Shaw 8 Linchi Shea 35 Jason Strate 33 Paul Turley 43 William Vaughn 42 Peter Ward 13 Joe Webb 10 John Welch 49 Allen White 30 Thiago Zavaschi 56

Trang 10

brief contents

P ART 1 A RCHITECTURE 1

Trang 11

P ART 5 B USINESS INTELLIGENCE 395

Trang 12

xi

Trang 14

contentspreface xxxv

acknowledgments xxxix about Operation Smile xli about this book xliii about the editors xlv about SQL Server MVPs xlvi

P ART 1 A RCHITECTURE 1

Trang 15

2 “Yes, we are all individuals”

A look at uniqueness in the world of SQL 16

R OB F ARLEY

Primary keys 17Unique constraints 18Unique indexes 19

Advantages of the unique index 19Advantages of the unique constraint 20

The good and the bad of DISTINCT 20DISTINCT or GROUP

BY 21Are they needed at all? 22Unnecessary grouping 23 Being guided by “that” error 24

C HRIS S HAW

IDENTITY case in point 27Database design and scalability 28

Overnormalized 30Undernormalized 30

GUIDs as primary keys 31System-generated integers as primary keys 32Generating your own ID values 32

Trang 16

RAID 0 49RAID 1 50RAID 5 51RAID 6 51

RAID 10 52RAID 50 52When to use RAID 5 52

When to use RAID 6 53When to use RAID 10 53

Index files 54Transaction log files 54tempdb database 54

Correcting disk alignment on Windows 2003 and earlier 55

Correcting disk alignment in Windows 2008 and later 56

Correcting after the partition has been created 56Aligning

on the array 56

Snapshots with a VSS-enabled storage array 57Snapshots

with a non-VSS-enabled storage array 57Snapshots as a backup

process 58Using snapshots to present storage to downstream

Trang 17

P ART 2 D ATABASE ADMINISTRATION 65

7 Increasing availability through testing 67

A LLAN H IRT

G AIL S HAW

Recovery model and availability of log backups 80SQL Server Edition 80Page type of the damaged page 80

G REG L ARSEN

J OE W EBB

Trang 18

J OHN M AGNABOSCO

Our superpowers 106Tools of the trade 107

P AWEL P OTASINSKI

P ETER W ARD

Trang 19

Surface area configuration 132Sysadmin membership 134

Policy-Based Management with Central Management

R ODNEY L ANDRUM

Utility Explorer—best tools for the DBA 146

S ATYA S HYAM K J AYANTY

Trang 20

T OBIASZ J ANUSZ K OPROWSKI

Service Level Agreements: the context for high

P ART 3 D ATABASE DEVELOPMENT 175

A ARON B ERTRAND

Trang 21

Inline table valued function solution 190Set-based solution 191

J OHN P AUL C OOK

S ERGIO G OVONI

SQL Server 2005 and 2008 solution 201SQL Server Denali solution 201Comparing execution plan results 202

Tips for using SEQUENCE 203Restrictions 203

H UGO K ORNELIS

…But do you need it at all? 212Representations and conversions 213How about NULL? 214

Starting the project 214Adding the fields for the native representation 215Editing the signature 215Converting between

Trang 22

Background 224An incredibly brief introduction to regular expressions, matches, and groups 225Regular expressions and SQL Server 226Regular expressions and the NET Framework 226

B EN M ILLER

Operating system configuration 247SQL Server configuration 248

Trang 23

Unit test for databases 256T-SQL unit test walkthrough 257

M LADEN P RAJDIC ´

D ENIS R EZNIK

Using the HierarchyId data type 279Physical HierarchyId data organization 280

Depth-first indexes 283Breadth-first indexes 284

A LLEN W HITE

Security 288Message types 289Contracts 289 Queues 289Services 289Conversations 290 Endpoints 290Routes 290Remote service binding 291

Trang 24

P ART 4 P ERFORMANCE TUNING AND OPTIMIZATION 297

G LENN B ERRY 299

G RANT F RITCHEY

OPTIMIZE FOR 313WITH RECOMPILE 315Local variables 316Plan guides 316Turn off parameter sniffing 318

Trang 25

An introduction to waits and queues 331

R OBERT P EARL

Why use wait stats? 332Wait type categories 332

General I/O issues 339Buffer I/O latch issues 339Blocking and locking 340CPU pressure 340Parallelism 340Memory pressure 341

L INCHI S HEA

Trang 26

B RAD M M C G EHEE

Start with standard performance-tuning techniques 357Take advantage of minimally logged operations if appropriate 358 Select a fast I/O subsystem 358Align disk partitions 358 Remove physical file fragmentation 358Preallocate transaction log file size 359Separating data and log files 359Managing virtual log files 360Perform transaction log backups often 360Schedule database maintenance during slow times 361

SELECT columns 364Data 364Sketch 365 Pseudocode 366

Too much data 367Functions 367Non-SARGable WHERE Clauses 368

T IM C HAPMAN

Trang 27

Data collector sets using PAL template files 375Logman 376 SQLDiag 376

Counter Log 377Threshold File 378Questions 380 Output Options 380File Output 381Queue 381 Execute 381

J UNGSUN K IM

P ART 5 B USINESS INTELLIGENCE 395

report part library 397

J ESSICA M M OSS

Level 1 400Level 2 400Level 3 401Level 4 401

Creating the initial report part 402Using report parts and change requests 403Existing report part changes and publication 403

Trang 28

G REG L OW

W ILLIAM (B ILL ) V AUGHN

Adding a report element property expression 412Coding a report Code property expression 414

Trang 29

Create a DNS entry for the NLB cluster application 437Configure the server network cards 437

R OBERT C AIN

Creating the main dataset 450Creating the parameter list shared dataset 451

Trang 30

A NDY L EONARD

File it 496Ignore it 496Update the fact later 497

Trang 31

T IM M ITCHELL

Before we get started…a word of caution 516Sources, destinations, and transformations…oh my! 516Synchronous and asynchronous behavior 518Script component inputs and outputs 519Into the code 520

Surrogate key generation 531Data update strategy 532

Alerting 533Recovery and restart ability 533Audit, balance, and control support 535Runtime event logging 535ETL metadata and reporting 536

J OHAN Å HLÉN

Sample usage scenarios 539Technology overview 539

Creating the Visual Studio project 539Creating the relational database emitter 540Creating the Analysis Services emitter 540

Trang 32

Creating the SSAS database 540Creating the data sources 541 Creating the Data Source View 542Creating the dimensions 543 Creating the cubes 545

Scripting databases 554Modules and snap-ins 555

DAX data types 569Sample database 570

Golden rules 571Functions that return a single date 571 Functions that return a table of dates 572Functions that evaluate expressions over a time period 573

Trang 33

G OGULA A RYALINGAM

Cards (or images) 578Slicing and dicing options 579Filtering and sorting options 579

Trang 34

index 617

Trang 36

preface

This is the second volume of a book that many people thought would never see thelight of day In early 2007, the editor of the first volume, Paul Nielsen, had an extraor-dinary idea I’ll let him tell you about how this idea came into being, by including asection from the preface to Volume 1:

Each year Microsoft invites all the MVPs from every technology and country to

Redmond for an MVP Summit—all top secret—“don’t tweet what you see!”

During the MVP Summit, each product team holds a series of presentations

where they explain their technologies, share their vision, and listen to some

honest feedback At the 2007 MVP Summit in Seattle, Bill Gates presented his

vision of the future of computing to the MVPs and then took questions for about

an hour I really enjoy these dialogues I get the sense that if BillG wasn’t the

founder of Microsoft, he’d make a great MVP You can tell he likes us as fellow

Geeks, and he’s rather candid in the MVP Q&A time It’s one of my favorite parts

of the MVP Summit

During the Q&A, the lines at the microphones are far too long to bother to join,

so I daydream a few questions I’d ask BillG:

■ As the world’s wealthiest Geek, what can you tell me about your PC?

■ Even with all your accomplishments, do you still find the most happiness

and satisfaction with your family?

■ Do you play Age of Empires 2, and if so, want to join me in a game?

■ Kirk or Picard?

■ Can I buy you lunch?

And then I thought of a good, deep, Charlie Rose-type of question: “Centuries

from now, would you rather be remembered as the guy who put a computer on

every desk, or as the guy who ended malaria and fought the good fight against

poverty?” As I try to guess what BillG might say, the answer is obvious I’m glad

that BillG’s intellect and resources are being directed at improving the human

condition, and as an original Windows fan I’m proud of BillG But the answer to

Trang 37

my question is both—Windows has already done as much to fight poverty as will

the Bill and Melinda Gates Foundation

Toward the end of the Q&A time, which was mostly taken up with technical

questions, I was thrilled to hear one of the MVPs ask for his advice as a

philanthropist BillG said that we should all be involved in our communities and

give of ourselves in creative ways: at the library, at schools, and with charities “Do

philanthropy where you are.” This idea of giving of ourselves is central to the

MVP community

Paul then went on to describe how he decided he could make a difference “where hewas” by writing about his passion, SQL Server, and using it to create a charity book tohelp children He enticed me into the project, and after communicating with the rest

of the SQL Server MVPs to determine if there was enough interest to make a project ofthis type viable, together we started approaching publishers

It didn’t take long to find that Manning Publications was extremely interested inproducing this kind of project Michael Stephens liked both the community aspect ofthe project and the charity goals Manning also offered us a higher-than-usual authorroyalty, because we were giving it all to charity We recruited four other prominentMVPs to help with the editing, and the project was underway

A project such as this had never been done before We had 53 independentauthors from all around the world trying to collaborate Figuring out how to managethe technical editing and rewrites, and dealing with writers who were technicallyextraordinary but lacking in some writing skills, and deciding what to do with a chap-ter that came in at 40 pages when all the rest were 10–15 pages, made the projectmuch more time-consuming than we expected Many of the MVPs who had writtenchapters early in the process despaired of ever seeing their work in print

But then it all seemed to come together, just in time for the 2009 PASS Conference,which is the largest conference in the world for SQL Server professionals The book hadbeen available for preorder, and by the time the conference started, the preordersalone had earned the chosen charity more than $10,000! Manning made an all-outeffort to get 200 copies of the book available in print to sell at the conference Almostthree dozen of the MVP authors were speaking at the conference, and they told theiraudiences about this remarkable work we had done On the Thursday of the confer-ence, right after lunch, we launched Volume 1 in a special event in the vendor area andfollowed this with the most popular book-signing in PASS history Most of the attendingauthors stood behind a long table, and eager readers flowed by in front of us, gettingautographs from all the authors present All 200 copies of the book were sold, which wasanother PASS record, and many people who wanted a copy weren’t able to get one andparticipate in the signing Although my hand was numb from signing my name so manytimes, it was the most exciting event of my professional life Volume 1 was so wellreceived that there was immediate talk of another one We all needed a rest, however,and we needed to give the community time to absorb the first terrific volume But in late

2010, Paul and I decided it was time to start thinking about Volume 2

Trang 38

Paul and I switched roles: he stepped down from the overall editor role to become

a section editor, and I became the overall editor Kimberly Tripp, Paul Randal, andGreg Low stayed on as section editors for the new volume, and we brought in LouisDavidson and Brad McGehee as new section editors Manning was more than happy

to continue to support us with its publishing team

Like the first volume, this one is divided into five sections aligned with the five jobroles dealing with SQL Server: database architecture and design, database develop-ment, database administration, performance tuning and optimization, and businessintelligence There was no rigid organization to the outline—MVPs were simply asked

to submit abstracts for chapters that they wanted to write, and those abstracts weredirected to the appropriate section editors As in the first volume, the contents aredriven by the MVPs’ individual passions, not by a comprehensive feature list The sec-tion editors selected the best abstracts, but we committed to the idea that every MVPwho wanted to contribute to the book could contribute We had a much tighter dead-line for this volume and also a much stricter page count limit, and we limited eachauthor to a single chapter But we didn’t restrict what the authors could write, andonly insisted that it be never-published material in a topic area that wasn’t specificallyaddressed in Volume 1 So this volume is completely new material!

To select the charity, we collected nominations from the participating MVPs withthe restriction that the charity had to be a secular group that benefited childrenaround the world And we wanted to give to a smaller charity—we didn’t want ourcontribution to be added to a billion-dollar fund The vote this time was overwhelm-ing in favor of Operation Smile, which you can read about on page xli

I’d like to include another paragraph from the preface to the first volume, becausethere is no way I can say this better than Paul did:

If you are reading this book, then you are “rich.” Considering your place in

human history, you’re wealthier than most kings of centuries past—you are well

educated, your grocery store shelves are full, you have a family doctor For too

many in the world, that is not the case There are communities without clean

water, children hurting from war, and AIDS orphans who have no family or place

to sleep When one ponders the immense need and poverty in the world, it’s

easy to become overwhelmed with hopelessness How can a single drop of ink

change the color of an ocean? But we have no other option than to do what we

can My philosophy is that of Confucius: “It is better to light one small candle

than to curse the darkness.” Even BillG can’t heal the world, but we can each

make a difference

By buying this book, you’ve supported Operation Smile We want to reiterate BillG’ssuggestion that we can all find ways to do philanthropy where we are, and this book isone way to start doing that, both for the authors and for the readers

Welcome to SQL Server MVP Deep Dives, Volume 2—a collaborative work by 64

pas-sionate SQL Server MVPs

KALEN DELANEY

Trang 39

xxxviii

Trang 40

To Marjan Bace, our publisher, thank you for helping us refine the originalconcept, supporting the project from the very first day of Volume 1, and partneringwith us.

To Michael Stephens, Cynthia Kane, Liz Welch, Linda Recktenwald, Mary Piergies,Barbara Mirecki, Candace Gillhoolley, Ozren Harlovic, Marija Tudor, and the rest ofthe team at Manning Publications—thanks for believing in this project and stickingwith it to the end

A big thanks to Victor Isakov, Dave Dustin, Aaron Nelson, Denis Gobo, and MikeWalsh for contributing their time as technical editors Your help was invaluable! And ahuge showering of gratitude to Stacia Misner, Jen Stirrup, Rob Farley, and RobertPearl who stepped up at the last minute to help us deal with an unexpected crunch!

To the reviewers who read early versions of the manuscript and provided helpfulfeedback: Amos Bannister, Nikander Bruggeman, Margriet Bruggeman, Dave Corun,Sanchet Dighe, Richard Handloff, Peter Lee, Massimo Perga, Richard Siddaway, IanStirk, and Deepak Vohra

Many thanks to Ed Lehman and Ed Hickey, our SQL Server product team MVPLiaisons, for their support and the many good times

To our MVP leads through the years—Shawn Aebi, Paul Wehland, Stephen Dybing,Ben Miller, Alison Brooks, Suzanna Moran, Ryan Bolz, and others internation-ally—thank you for supporting our community efforts

Ngày đăng: 13/04/2017, 14:20

TỪ KHÓA LIÊN QUAN

w