Course Topics

38
Course Topics Administering SQL Server 2012 Jump Start 01 | Install and Configure SQL Server 04 | Manage Data 02 | Maintain Instances and Databases 05 | Implement Security 03 | Performance Optimization and Troubleshooting 06 | High Availability Options

description

Course Topics. 04 | Manage Data. George Squillace | Senior Technical Trainer – New Horizons Great Lakes Richard Currey | Senior Technical Trainer – New Horizons United. Module 4 Overview. Backups and Backup Strategies Restores and Recovery Move Databases and Database Files - PowerPoint PPT Presentation

Transcript of Course Topics

Page 1: Course Topics

Course Topics

Administering SQL Server 2012 Jump Start01 | Install and Configure SQL Server 04 | Manage Data

02 | Maintain Instances and Databases 05 | Implement Security

03 | Performance Optimization and Troubleshooting 06 | High Availability Options

Page 2: Course Topics

Click to edit Master subtitle style

04 | Manage DataGeorge Squillace | Senior Technical Trainer – New Horizons Great LakesRichard Currey | Senior Technical Trainer – New Horizons United

Page 3: Course Topics

Module 4 Overview• Backups and Backup Strategies• Restores and Recovery• Move Databases and Database Files• Ensure Database Integrity• Indexes, Statistics, and Maintenance

Page 4: Course Topics

Topic: Backups and Backup Strategies

Page 5: Course Topics

Topic: Backups and Backup Strategies• User Database Recovery Models• Backup Statements and Typical Options• Backup Integrity Testing• System Database Backups

Page 6: Course Topics

User Database Recovery ModelsRecovery Model Details

Full • Point in time recovery• Failed media recovery

Bulk-logged • Interim recovery model used to reduce logging

• Point in time recovery is not available within bulk options

Simple (truncate log on checkpoint)

• Log backups are not available, no point in time recovery

• Small databases or databases that can be rebuilt from other source data

Page 7: Course Topics

Backup Statements and Typical OptionsStatement Typical Options

– BACKUP DATABASE– BACKUP LOG

– FORMAT– CHECKSUM– COPY_ONLY– WITH INIT/NOINIT– WITH DIFFERENTIAL– WITH MIRROR TO– COMPRESSION– NOTRUNCATE– NORECOVERY– CONTINUE_AFTER_ERROR

Page 8: Course Topics

Backup Integrity Testing• RESTORE VERIFYONLY FROM device• RESTORE HEADERONLY FROM device• RESTORE FILELISTONLY FROM device• RESTORE LABELONLY FROM device

Page 9: Course Topics

System Database Backups• Vital to the recovery of the instance• Certain system database corruptions cause the

failure of the SQL Server or SQL Server Agent Services

• Don’t change the system database recovery models

Page 10: Course Topics

DEMOExecuting BACKUP Statements and Testing Backup Integrity

Page 11: Course Topics

Topic: Restores and Recovery

Page 12: Course Topics

Topic: Restores and Recovery• Recovery Process and Phases• Types of Restores• Restore Statements and Typical Options• System Database Restores–Special Considerations

Page 13: Course Topics

Recovery Process and Phases• Recovery phases– Data copy– Redo– Undo

• Recovery process– Don’t make it worse…calm yourself!– Tail log backup (remember the demo?)– Restore full-database backup– Restore most recent differential backup– Restore all logs from the most recent differential– Restore the tail of the log and recover the database

Page 14: Course Topics

Types of Restores• Complete database restore in simple recovery• Complete database restore in full recovery• System database restore• File restore• Online restore• Piecemeal restore• Page restore

Page 15: Course Topics

Restore Statements and Typical OptionsStatements Typical Options

• RESTORE DATABASE – WITH RECOVERY / NORECOVERY

– WITH FILE = 1– WITH REPLACE– WITH MOVE– WITH STANDBY

•RESTORE LOG – WITH STANDBY– WITH STOPAT = time– WITH STOPATMARK /

STOPBEFOREMARK

Page 16: Course Topics

System Database Restores–Special Considerations• Recovering master when not corrupt• Recovering master when corrupt• Recovering model when corrupt• Recovering MSDB when corrupt• Recovering resource when corrupt• “Recovering” TempDB when corrupt

Page 17: Course Topics

DEMORestoring and Recovering a Database and Point-in-Time Recovery

Page 18: Course Topics

Topic: Move Databases and Database Files

Page 19: Course Topics

Topic: Move Databases and Database Files

• Moving and Copying Entire Databases to Other Instances

• Relocate Database Files Within an Instance• System Databases Require Special Treatment

Page 20: Course Topics

Moving and Copying Databases to Other Instances• SSMS / sp_detach_db / SSIS• CREATE Database … FOR ATTACH (which now

supercedes sp_attach_db)• Requires the use of logical filenames (use

sys.database_files)

Page 21: Course Topics

Relocate Database Files Within an Instance• ALTER DATABASE• Requires the Use of Logical Filenames (use

sys.database_files)

Page 22: Course Topics

System Databases Require Special Treatment• Moving master requires setting startup options in

SQL Server Configuration Manager• Other system databases require the use of ALTER

DATABASE and a SQL Server Service restart

Page 23: Course Topics

DEMOMoving a User Database

Page 24: Course Topics

Topic: Ensure Database Integrity

Page 25: Course Topics

Topic: Ensure Database Integrity• Overview of DBCC Statements• DBCC CHECKDB Execution Options• DBCC CHECKDB Repair Options

Page 26: Course Topics

Overview of DBCC Statements• Corruption is rare but possible• There are Many DBCC commands– Informational statements• DBCC OPENTRAN

– Validation statements• DBCC CHECKDB

–Maintenance statements• DBCC FREEPROCCACHE

–Miscellaneous statements• DBCC TRACEON/TRACEOFF

Page 27: Course Topics

DBCC CHECKDB Execution Options• Purpose of DBCC CheckDB is to validate database integrity• When DBCC CheckDB executes, it also spawns:

– DBCC CHECKALLOC– DBCC CHECKTABLE– DBCC CHECKCATALOG

• PHYSICAL_ONLY• NOINDEX• EXTENDED_LOGICAL_CHECKS• TABLOCK• ALL_ERRORMSGS• NO_INFOMSGS• ESTIMATEONLY

Page 28: Course Topics

DBCC CHECKDB Repair Options• Back up the database before performing any DBCC repair• But if you have to repair…

– The database must be in single user mode (ALTER DATABASE)– REPAIR_REBUILD

• Causes no loss of data integrity within the database• Rebuilds indexes and deallocates corrupt pages• Does not involve data loss• Only works in certain circumstances

– REPAIR_ALLOW_DATA_LOSS• Repair should absolutely be the last resort• Database damage is likely• If the database is in Emergency Repair mode (ALTER DATABASE) special repairs are

attempted with this option

• Make sure that the original cause of the corruption is resolved

Page 29: Course Topics

DEMOUsing DBCC CheckDB

Page 30: Course Topics

Topic: Indexes, Statistics, and Maintenance

Page 31: Course Topics

Topic: Indexes, Statistics, and Maintenance

• Table Structures• What Is An Index?• What Are Statistics?• Index Fragmentation• Index and Statistics Maintenance

Page 32: Course Topics

Table Structures• Heap– Default table structure– No order of table pages (logically or physically)– No order of rows within a page

• Clustered Table– Imposed when a clustered index is created

• Potential result of creating a primary key constraint, a unique constraint or (unlikely) the CREATE CLUSTERED INDEX statement

– Logical ordering of table pages– Physical ordering of rows within a page– Only one clustered index per table

Page 33: Course Topics

What Is an Index?• List of sorted values–May or may not impose uniqueness of values

• Stored in pages outside of the table• Reading index pages on well-designed indexes is

often more efficient in locating rows than reading the whole table (scan)

• Clustered index vs. a non-clustered index• Created by using constraint creation or CREATE

INDEX

Page 34: Course Topics

What Are Statistics?• Cardinality–number of members in a set• (Distribution) statistics objects sample data to help obtain

cardinality estimates for tables and indexed views• Help determine an optimal execution plan– May aid in index selection and query processing– Join type (nested loop, hash)– Join order (table 1, table 2, or table 2, table 1)

• Statistics are auto or manually created– May include a sampling of values or all values

• Statistics become outdated as data changes

Page 35: Course Topics

Index Fragmentation• Fragmentation is internal and/or external

– Internal• The inefficient use of space within database pages

– External• Pages spread (non-contiguously) within a data file

• Some amount of internal fragmentation may be desirable– Internal fragmentation can be controlled with the FILLFACTOR and PAD_INDEX

options of the Create Index and Create Table statements

• External fragmentation is never desirable• Fragmentation is determined by:

– GUI– sys.dm_db_index_physical_stats (DMF)

• Checks fragmentation database-wide, table-wide, for a specific index or a specific partition

Page 36: Course Topics

Index and Statistics Maintenance• Index maintenance

– ALTER INDEX … REORGANIZE– ALTER INDEX … REBUILD

• Enterprise Edition Index Maintenance features– ALTER INDEX … ALL

• Statistics maintenance– Auto create and update options– AUTO_UPDATE_STATISTICS_ASYNC– Forceful update with sp_UpdateStats

• Tools– Maintenance plans in SSIS– T-SQL agent jobs

Page 37: Course Topics

DEMODetermining Fragmentation and Performing Index Maintenance

Page 38: Course Topics

©2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, Office, Azure, System Center, Dynamics and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.