Microsoft SQL Server 2012 Step By Step

2y ago
19 Views
2 Downloads
2.93 MB
60 Pages
Last View : 1d ago
Last Download : 3m ago
Upload by : Olive Grimm
Transcription

MicrosoftSQL Server 2012Step by Step Patrick LeBlanc

Copyright 2013 by Patrick LeBlanc.All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by anymeans without the written permission of the publisher.ISBN: 978-0-7356-6386-2Third Printing: March 2015Printed and bound in the United States of America.Microsoft Press books are available through booksellers and distributors worldwide. If you need support relatedto this book, email Microsoft Press Book Support at mspinput@microsoft.com. Please tell us what you think ofthis book at soft and the trademarks listed at ctualProperty/Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property oftheir respective owners.The example companies, organizations, products, domain names, email addresses, logos, people, places, andevents depicted herein are fictitious. No association with any real company, organization, product, domain name,email address, logo, person, place, or event is intended or should be inferred.This book expresses the author’s views and opinions. The information contained in this book is provided withoutany express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, ordistributors will be held liable for any damages caused or alleged to be caused either directly or indirectly bythis book.Acquisitions Editor: Ken JonesDevelopmental Editor: Box Twelve CommunicationsProduction Editor: Melanie YarbroughEditorial Production: Box Twelve CommunicationsTechnical Reviewer: William AssafCopyeditor: Zyg Group, LLCIndexer: BIM Publishing ServicesCover Design: Twist Creative SeattleCover Composition: Zyg Group, LLCIllustrator: Rebecca Demarest

I would like to dedicate this book to my wife. When I amfrustrated and just want to quit, she finds a way to motivate meand drive me to get back on track. During the writing of thisbook, she never complained once about the long nights of typing. Instead she encouraged and supported me the whole time.Thank you sweetheart for all that you do for our family. I couldnot have done this without you.—Patrick LeBlanc

This page intentionally left blank

Contents at a GlanceIntroductionxixPart IGETTING STARTED WITH MICROSOFT SQL SERVER 2012Chapter 1Overview of Microsoft SQL Server 20123Chapter 2Installing, Configuring, and UpgradingMicrosoft SQL Server 20129Chapter 3Using SQL Server 2012 administration and development tools 21Part IIDESIGNING DATABASESChapter 4Designing SQL Server databases35Chapter 5Creating your first table49Chapter 6Building and maintaining indexes73Part IIIADVANCED DATABASE DESIGN TOPICSChapter 7Table compression95Chapter 8Table partitioning105Chapter 9Database snapshots117Chapter 10The SELECT statement123Part IVUSING TRANSACT-SQL (T-SQL)Chapter 11Advanced data retrieval topics141Chapter 12Modifying data151Chapter 13Built-in scalar functions163Part VCREATING OTHER DATABASE OBJECTSChapter 14Advanced T-SQL topics175Chapter 15Views193Chapter 16User-defined functions203Chapter 17Stored procedures215Chapter 18Data manipulation triggers225

viPart VISQL SERVER REPLICATIONChapter 19ReplicationPart VIIDATABASE MAINTENANCEChapter 20Backups255Chapter 21Managing and maintaining indexes and statistics271Chapter 22Maintenance plans283Part VIIIDATABASE MANAGEMENTChapter 23SQL Server Profiler293Chapter 24Extended Events303Chapter 25SQL Server security313Chapter 26Resource Governor333Chapter 27SQL Server Agent345Chapter 28Database Mail365Chapter 29Data definition triggers379Chapter 30Dynamic management objects387Part IXHIGH-AVAILABILITY SOLUTIONSChapter 31AlwaysOn399Chapter 32Log shipping421Index433About the Author453Contents at a Glance235

ContentsIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xixPart IGETTING STARTED WITH MICROSOFT SQL SERVER 2012Chapter 1Overview of Microsoft SQL Server 20123Business intelligence. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Database Engine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4T-SQL programming interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4Security subsystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5Replication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6SQL Server Agent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6High Availability and Disaster Recovery Tools . . . . . . . . . . . . . . . . . . . 7SQL Server Integration Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8SQL Server Management Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8Chapter 2Installing, Configuring, and UpgradingMicrosoft SQL Server 20129Editions of SQL Server 2012 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9Choosing hardware for SQL Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Software prerequisites. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11Before installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12SQL Server instances. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12Service accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13Collation sequences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Authentication modes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Installing SQL Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14Installing SQL Server from the Setup Wizard. . . . . . . . . . . . . . . . . . . 14vii

After installation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Assigning a TCP/IP port number to theSQL Server Database Engine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Opening a SQL Server instance port using Windows Firewall. . . . . 18How to upgrade to SQL Server 2012. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19In-place upgrade. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Side-by-side upgrade. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20Chapter 3Using SQL Server 2012 administration anddevelopment tools21Using SQL Server Books Online. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Using SQL Server Management Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23Using SQL Server Management Studio to createsolutions and projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Using SQL Server Data Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27Using SQL Server Configuration Manager. . . . . . . . . . . . . . . . . . . . . . . . . . . 30Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Part IIDESIGNING DATABASESChapter 4Designing SQL Server databases35Understanding SQL Server system databases. . . . . . . . . . . . . . . . . . . . . . . . 35master database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36tempdb database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36model database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36msdb database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37resource database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37distribution database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Understanding the SQL Server database structure . . . . . . . . . . . . . . . . . . . 38Creating a database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39Understanding arguments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Adding files and filegroups. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Detaching and attaching SQL Server databases. . . . . . . . . . . . . . . . . . . . . . 44viiiContents

Understanding database recovery models . . . . . . . . . . . . . . . . . . . . . . . . . . 47Simple model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Full model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Bulk-logged model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Chapter 5Creating your first table49Developing a naming standard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50Understanding schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52Understanding SQL Server data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54Numeric data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54String data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55Date and time data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Other data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Understanding column properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58Creating tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58Altering tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Understanding computed columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Adding constraints to a table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Primary key constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64Default constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Unique constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Check constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65Foreign key constraints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Understanding the FileTable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Creating database diagrams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .71Chapter 6Building and maintaining indexes73Index structure overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Clustered index structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76Nonclustered index structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78Columnstore index structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Contentsix

Adding index options. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82Adding included columns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85Adding filters to indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87Placing indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89Disabling and dropping indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Part IIIADVANCED DATABASE DESIGN TOPICSChapter 7Table compression95Understanding row compression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96Row compression with T-SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100Understanding page compression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101Page compression with T-SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103Estimating effects of compression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103Compression considerations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .104Chapter 8Table partitioning105Creating a partition function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106Using partition function arguments. . . . . . . . . . . . . . . . . . . . . . . . . . 106Creating a partition scheme. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Specifying partition scheme arguments . . . . . . . . . . . . . . . . . . . . . . 109Partitioning tables and indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .115Chapter 9Database snapshots117Understanding database snapshot prerequisites and limitations . . . . . . 117Creating and viewing database snapshots. . . . . . . . . . . . . . . . . . . . . . . . . . 118Dropping database snapshots. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119Reverting to a database snapshot. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .122xContents

Chapter 10 The SELECT statement123Writing a SELECT statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Sorting results. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Filtering data with the WHERE clause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126Using comparison operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126Using the BETWEEN operator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127Using the WHERE clause with multiple conditions. . . . . . . . . . . . . . 128Searching for a list of values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .129Using a wildcard search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Creating aliases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Using the JOIN operator to return data from multiple tables . . . . . . . . . 131Using INNER JOIN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131Using OUTER JOINs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Limiting the data returned in your result set. . . . . . . . . . . . . . . . . . . . . . . . 134Using TOP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Using DISTINCT and NULL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Using UNION to combine result sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .137Part IVUSING TRANSACT-SQL (T-SQL)Chapter 11 Advanced data retrieval topics141Pivoting and unpivoting data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Using the PIVOT operator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Using the UNPIVOT operator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144Paging data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Writing expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Using variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .150Contentsxi

Chapter 12 Modifying data151Inserting data into SQL Server tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Using the INSERT INTO statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 151Using sequence numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153Using the SELECT INTO statement. . . . . . . . . . . . . . . . . . . . . . . . . . . 155Updating data in tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156Updating rows while referencing multiple tables . . . . . . . . . . . . . . 157Deleting data from tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157Merging data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159Returning output data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161Chapter 13 Built-in scalar functions163Using date and time functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Deriving dates from parts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Differencing, modifying, and validating date values. . . . . . . . . . . . 166Using conversion functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167New SQL Server 2012 conversion functions. . . . . . . . . . . . . . . . . . . 169Using string functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170Using logical functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172Part VCREATING OTHER DATABASE OBJECTSChapter 14 Advanced T-SQL topics175Aggregating, windowing, and grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Performing aggregations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176Performing aggregations with groupings. . . . . . . . . . . . . . . . . . . . . 177Windowing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179New T-SQL windowing features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181Using the HAVING clause. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181xiiContents

Using SQL Server temporary objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182Common table expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182Table variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184Temporary tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186Handling T-SQL errors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187Controlling flow keywords. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189BEGIN END . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190IF ELSE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191WHILE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .192Chapter 15 Views193What are views?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193Creating indexed views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Referenced table requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Indexed view requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .202Chapter 16 User-defined functions203Understanding user-defined scalar functions. . . . . . . . . . . . . . . . . . . . . . . 204Parameterizing functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204Executing scalar functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208Understanding table-valued functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211Using table-valued functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213Limitations of functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .214Chapter 17 Stored procedures215Working with stored procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216Using the EXECUTE keyword. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218Parameterizing stored procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .220Dropping stored procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .224Contentsxiii

Chapter 18 Data manipulation triggers225Types of triggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225Creating triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226Altering triggers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229Dropping triggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Enabling and disabling triggers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .232Part VISQL SERVER REPLICATIONChapter 19 Replication235Types of replication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236Snapshot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236Transactional. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236Merge. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Replication agents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Snapshot Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Distribution Agent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Log Reader Agent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Merge Agent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Configuring replication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Monitoring replication. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .251Part VIIDATABASE MAINTENANCEChapter 20 Backups255Understanding backup devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255Full database backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257Differential database backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262Transaction log database backups. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264Restoring databases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .270xivContents

Chapter 21 Managing and maintaining indexes and statistics271Checking index fragmentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272Defragmenting indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272Reorganizing indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273Rebuilding indexes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275Checking index usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277Creating and updating database statistics. . . . . . . . . . . . . . . . . . . . . . . . . . 278Viewing database statistic options. . . . . . . . . . . . . . . . . . . . . . . . . . . 278Updating database statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .281Chapter 22 Maintenance plans283Performing database consistency checks. . . . . . . . . . . . . . . . . . . . . . . . . . . 283Creating maintenance plans. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284Using the Maintenance Plan Wizard. . . . . . . . . . . . . . . . . . . . . . . . . . 284Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .289Part VIIIDATABASE MANAGEMENTChapter 23 SQL Server Profiler293Understanding SQL Server Profiler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293Typical uses of SQL Server Profiler . . . . . . . . . . . . . . . . . . . . . . . . . . . 294Creating traces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294Filtering a trace. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298Creating trace templates. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300Running server-side traces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .302Chapter 24 Extended Events303Understanding the Extended Events architecture . . . . . . . . . . . . . . . . . . . 303Creating and configuring an Extended Events session . . . . . . . . . . . . . . . 304Using an Extended Events session to monitor system performance. . . . 308Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .311Contentsxv

Chapter 25 SQL Server security313Understanding principals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314Creating server logins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315Creating user-defined server roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320Creating database users. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322Creating built-in database roles. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325Configuring contained databases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327Creating a contained user. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329Benefits and limitations of contained databases. . . . . . . . . . . . . . . 330Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .331Chapter 26 Resource Governor333Enabling and disabling Resource Governor. . . . . . . . . . . . . . . . . . . . . . . . . 334Creating resource pools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336Creating a workload group. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338Using classifier functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340Testing classifier functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341Modifying Resource Governor configurations. . . . . . . . . . . . . . . . . . . . . . .

PTIIIAR V DATABASE MANAGEMENT. ChaPter 23 . SQL Server profiler 293. ChaPter 24 . extended events 303. Chapter 25 . SQL Server security 313. ChaPter 26 . rce Governoresour 333. Chapter 27 . SQL Server agent 345. ChaPter 28 . Database Mail 365. ChaPter 29 . Data definition triggers 379. ChaPter 30 . Dynamic

Related Documents:

Server 2005 , SQL Server 2008 , SQL Server 2008 R2 , SQL Server 2012 , SQL Server 2014 , SQL Server 2005 Express Edition , SQL Server 2008 Express SQL Server 2008 R2 Express , SQL Server 2012 Express , SQL Server 2014 Express .NET Framework 4.0, .NET Framework 2.0,

Microsoft SQL Server OLAP Client 2000 SP4 Microsoft SQL Server Analysis Services 2005 SP11 Microsoft SQL Server OLAP Client 2005 SP1 Microsoft SQL Server Analysis Services 2005 SP21 Microsoft SQL Server OLAP Client 2005 SP2 Microsoft SQL Server Analysis Services 20082 Microsoft SQL Server 2008

SQL Server 2005 SQL Server 2008 (New for V3.01) SQL Server 2008 R2 (New for V3.60) SQL Server 2012 (New for V3.80) SQL Server 2012 R2 (New for V3.95) SQL Server 2014 (New for V3.97) SQL Server 2016 (New for V3.98) SQL Server 2017 (New for V3.99) (Recommend Latest Service Pack) Note: SQL Server Express is supported for most situations. Contact .

MS SQL Server: MS SQL Server 2017, MS SQL Server 2016, MS SQL Server 2014, MS SQL Server 2012, MS SQL Server 2008 R2, 2008, 2008 (64 bit), 2008 Express, MS SQL Server 2005, 2005 (64 bit), 2005 Express, MS SQL Server 2000, 2000 (64 bit), 7.0 and mixed formats. To install the software, follow the steps: 1. Double-click Stellar Repair for MS SQL.exe.

4395 querying data with transact -sql (m20761) microsoft sql server 6552 querying microsoft sql server 2014 (m20461) microsoft sql server 1833 sql server performance tuning and optimization (m55144) microsoft sql server 4394 updating your skills to sql server 2016 (m10986) microsoft sql server

11.4.7462.6 Microsoft SQL Server 2012 Native Client Microsoft SQL Server 2017 (64-bit) 14.0.1000.169 Microsoft SQL Server 2017 (64-bit) Microsoft SQL Server 2017 Setup (English) 14.0.1000.169 Microsoft SQL Server 2017 Setup (English) Microsoft SQL Server 2017 T-SQL Language Service 14.0.1000.169

70 Microsoft SQL Server 2008: A Beginner’s Guide SQL_2008 / Microsoft SQL Server 2008: ABG / Petkovic / 154638-3 / Chapter 4 In Transact-SQL, the use of double quotation marks is defined using the QUOTED_ IDENTIFIER option of the SET statement. If this option is set to ON, which is theFile Size: 387KBPage Count: 26Explore furtherLanguage Elements (Transact-SQL) - SQL Server Microsoft Docsdocs.microsoft.comThe 33 languages of SQL Server Joe Webb Blogweblogs.sqlteam.comThe Language of SQL Pdf - libribooklibribook.comSql And The Standard Language For Relational Database .www.bartleby.comdatabase - What are good alternatives to SQL (the language .stackoverflow.comRecommended to you based on what's popular Feedback

4. To upgrade SQL Server 2008 SP3 Express to SQL Server 2012 SP2 Express, launch th e installer for SQL Server 2012 SP2 Express, and then follow the wizard. 5. Select the Upgrade from SQL Server 2005, SQL Server 2008 or SQL Server 2008R2 option under the Installation option. The Upgrade to SQL