Denny Cherry mrdenny@dcac.co @mrdenny

Preview:

Citation preview

Introduction to SQL Server Management for the Non-DBA

Denny Cherrymrdenny@dcac.cotwitter.com/mrdenny

DBI-B220

Files, File Groups, DisksBackupsRecovery ModelDatabase MaintenanceCompressionCorruptionCompatibility LevelIndexes

Agenda

Each database is made up of at least two filesOne file is dataOne file is transaction log

Files, File Groups, Disks

http://www.flickr.com/photos/photomequickbooth/4011249096/

File Groups are made up of filesFiles hold the dataDisks Hold Files

Files, File Groups, Disks

http://www.flickr.com/photos/photomequickbooth/4011249096/

Tables created within file groupsAllows tables to be spread across disksFile groups typically only need one 1 file

Files, File Groups, Disks

https://www.flickr.com/photos/andrewnebbett/5356889496/

Single file group4-8 files for most instancesMore if using lots of temporary tables, pivoting

TempDB Database

https://www.flickr.com/photos/rachaelvoorhees/4988206451/

Three Recovery Models AvailableSimpleBulk-LoggedFull

Used to control amount of loggingControls recoverability

Recovery Models

http://www.flickr.com/photos/decade_null/142235888/

Minimal LoggingNo Point In Time RecoveryDoes Not Disable Logging

Simple Recovery Model

http://www.flickr.com/photos/noii/1337970464/

Some commands are bulk loggedMost commands are fully loggedPoint In Time Recovery Supported

Bulk Logged Recovery Model

http://www.flickr.com/photos/4nitsirk/3778043845/

Almost nothing is bulk loggedPoint in time recovery is supportedFull Data Protection

Full Recovery

http://www.flickr.com/photos/dok1/5623000758/

3 Different Kinds of BackupsFull BackupsDifferential BackupsTransaction Log Backups

Advanced Backup OptionsFile Group Backups

Backups Saved On Another Machine

Backups

http://www.flickr.com/photos/gemstone/406866312/

Makes a point in time copy of the databaseDatabase is in the state the database was at the end of the backupShould be done daily or weekly

Full Backups

Backs up changes since last full backupUsually used for reporting databasesOptional database backup type

Differential Backups

Backs up transactions since last log backupFrequency should be dictated by business need (RPO)Required for full or bulk logged recovery model

Transaction Log Backups

Full RestoreDifferential RestoreTransaction Log RestorePage Level RestoreFile Group Restore

Restoring Data

http://www.flickr.com/photos/fun_flying/2959307155/

Databases need TLCIndex RebuildingIndex DefragmentingUpdate Statistics

Database Maintenance

http://www.flickr.com/photos/wjlonien/6309343565/

Database MaintenanceIndex Rebuild

Can be online or offline depending on version, edition and column data typesCreates new indexes then drops old indexUpdates Statistics on index

Index Defrag

Always OnlineMoves data around pages row by rowOnly moves rows that need to be moved

http://www.flickr.com/photos/usnavy/5488581781/

How SQL Server figures out how to access dataStatistics are used to create an execution planStatistics are a sampling of the values within a table or indexStatistics contain up to 200 samples of the values within the tableStatistics track the number of values between sampled values

Statistics?

http://www.flickr.com/photos/franganillo/3676227162/

Statistics?

Compression

https://www.flickr.com/photos/smithser/6122836965/

• Saves space within:• The database• Memory• Backups

• Costs CPU speed, but usually worth it• Data Compression is Page or Row• Backup Compression is an on or off

All databases can become corruptCorruption is usually a hardware problemCorruption should be checked for regularlyDepending on what is corrupt it may be repaired without data lossCorruption is checked for and repaired using DBCC CHECKDBCorruption will happen, how you prepare for it will determine how easily you can survive itSome corruption can’t be repaired and must be restored from a backup

Corruption

Compatibility levels tell SQL Server which language syntax to supportDoes not effect the version of the SQL Server the database can be restored toSQL Supports several down level compatibility levels.

SQL 2012 supports SQL 2005 and upSQL 2008 R2 and below support SQL 6.5 and up

Compatibility Level

Used to speed up queriesSorted based on the columns within the indexCauses duplicate data to be storedTrades space for speedIndexes are ½ art and ½ science

Indexes

http://www.flickr.com/photos/annarbor/4350627292/

ClusteredNonclusteredFull TextSpatialColumnStoreXMLSemantic Search

Indexes

http://www.flickr.com/photos/tryingyouth/2456237/

Indexes

Indexes

Indexes aren’t freeEvery index added slows down INSERT/UPDATE/DELETE operationsOnly create indexes where the cost of having the index is worth itUnused indexes can be removed from the database

Indexes

http://dcac.co/res/teched2014

Additional Reading…

27 Hands on Labs + 8 Instructor Led Labs in Hall 7

DBI Track resources

Free SQL Server 2014 Technical Overview e-book

microsoft.com/sqlserver and Amazon Kindle StoreFree online training at Microsoft Virtual Academy

microsoftvirtualacademy.com Try new Azure data services previews!Azure Machine Learning, DocumentDB, and Stream Analytics

Resources

Learning

Microsoft Certification & Training Resources

www.microsoft.com/learning

Developer Network

http://developer.microsoft.com

TechNet

Resources for IT Professionals

http://microsoft.com/technet

Sessions on Demand

http://channel9.msdn.com/Events/TechEd

Please Complete An Evaluation FormYour input is important!TechEd Schedule Builder CommNet station or PC

TechEd Mobile appPhone or Tablet

QR code

Evaluate this session

© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, 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.

Recommended