supporting sqlserver
DESCRIPTION
TRANSCRIPT
![Page 1: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/1.jpg)
Supporting SQL Server – When YouSupporting SQL Server – When You’’d d Really Rather NotReally Rather NotDon JonesDon JonesConcentratedTech.com
Pre-requisites for this presentation:
1) Strong understanding of basic Windows administration
Level: Advanced
![Page 2: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/2.jpg)
This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it
within your own organization however you like.
For more information on our company, including information on private classes and upcoming conference appearances, please
visit our Web site, www.ConcentratedTech.com.
For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg
This work is copyright ©Concentrated Technology, LLC
![Page 3: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/3.jpg)
About the InstructorAbout the Instructor
Don Jones Contributing Editor,
technetmagazine.com IT author, consultant, and speaker Co-founder of Concentrated Technology Seven-time recipient of Microsoft’s Most
Valuable Professional (MVP) Award Author and Editor-in-Chief for Realtime
Publishers Trainer for www.CBTNuggets.com
![Page 4: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/4.jpg)
About this SessionAbout this Session
Primarily demo and how-to… not so much with the slides
Most queries I run I will save (remind me) – I’ll make these available on my Web site (see slide at end of deck) for you to download, along with this deck
![Page 5: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/5.jpg)
About YouAbout You
A Windows admin stuck managing one or more SQL Server installs because you’re “the Microsoft guy/gal”
Not particularly interested in SQL Server Just stuck running it
![Page 6: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/6.jpg)
SUPPORTING SQL SERVERSUPPORTING SQL SERVERPart 1
![Page 7: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/7.jpg)
How SQL Server WorksHow SQL Server Works
Database is a logical+physical structure – think of it as a container
Contains one or more tables, which represent entities that an application works with
Tables consist of columns and rows – kinda like an Excel spreadsheet
![Page 8: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/8.jpg)
Physical StoragePhysical Storage
SQL stores data in database files (MDF, NDF)
Organized into 8KB pages, which hold 1+ rows of data each
An entire row must always fit on a page; large data chunks may be spread across multiple pages
![Page 9: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/9.jpg)
FilestreamsFilestreams
New in SQL2008: Ability to store large data in normal files outside the database, and only keep a pointer in the database
Shares the files via a normal file share Impacts some features such as
database mirroring and certain forms of replication
![Page 10: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/10.jpg)
Querying DataQuerying Data
SQL Server loads needed pages into memory to access their data
Uses a query optimizer to analyze incoming queries and decide the best way to get the needed data
Optimizer relies on internal statistics that tell it the physical condition of the data (fragmentation level, etc)
![Page 11: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/11.jpg)
Changing DataChanging Data
SQL Server loads affected pages into RAM
Changes pages in RAM and logs the change to a transaction log (LDF file)
Doesn’t write the affected pages back to disk immediately
Log serves as a form of bakcup
![Page 12: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/12.jpg)
Committing DataCommitting Data
When SQL writes affected pages back to disk, it “marks” them as “committed” in the log
It does not clear the from the log
![Page 13: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/13.jpg)
Recovery ModeRecovery Mode
SQL Server automatically starts in recovery mode
It checks to see if any uncommitted transactions are in any logs
If it finds them, it re-runs the transactions and commits them immediately
This deals with “we had uncommitted data in RAM and the server crashed”
![Page 14: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/14.jpg)
Backup ModelBackup Model
Full Backup: All of the data. Clears (‘truncates’) committed transactions from the log – because now they’re safe
Incremental: Everything since the last full or incremental
Log: Backs up just the log file
![Page 15: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/15.jpg)
Backup ExampleBackup Example
1am: Full backup
9am: Incremental
10am: Log 11am: Log 11:05: CRASH
Restore the full, the incremental, both logs
Will lose everything from 11:00-11:05
Log backups are VERY fast
![Page 16: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/16.jpg)
TipsTips
Keep logs on separate disks/volumes from the data
Backup to a file, and then grab the backup file to tape – or use an agent to backup directly to tape
SQL itself can also backup directly to tape for locally-attached tape drives
![Page 17: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/17.jpg)
PerformancePerformance
When new objects (tables, etc) are created in the database, you can designate which file they go to
One MDF file per database, multiple NDF files
Spread files across disks to improve access times
Backup/restore the files as a unit by having all files in the same filegroup
![Page 18: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/18.jpg)
IndexesIndexes
Help SQL Server find sorted data faster Each table can have one clustered index
– physically stores data in the desired order
Can have 1+ nonclustered indexes – pointers to the actual physical data
Indexes are also stored on 8KB pages
![Page 19: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/19.jpg)
Index Fragmentation (Page Splits)Index Fragmentation (Page Splits)
Happens when a page is full, and SQL needs to insert data “in between” existing data
The page is split: Half the data is copied to a new page at the end of the data file, making room for the new data
Results in index fragmentation
![Page 20: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/20.jpg)
Index MaintenanceIndex Maintenance
Periodically rebuild/reorganize indexes Can specify amount of free space to
leave – leaves room for growth w/out splits
Allow SQL to auto-update statistics – helps it understand how useful each index is on a continuing basis
![Page 21: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/21.jpg)
Index TricksIndex Tricks
An index can contain more than one column
A covering index is one which contains all the data needed to satisfy a query – without having to go to the actual data
![Page 22: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/22.jpg)
Non-Covering IndexNon-Covering Index
SELECT Name,ID FROM Users WHERE Name LIKE ‘D%’
ID Name
4 Erin
5 Don
6 Dave
Dave
Don
Erin
CICINCINCI
![Page 23: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/23.jpg)
Covering IndexCovering Index
SELECT Name FROM Users WHERE Name LIKE ‘D%’
ID Name
4 Erin
5 Don
6 Dave
Dave
Don
Erin
CICINCINCI
![Page 24: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/24.jpg)
Index DownsidesIndex Downsides
Indexes improve lookup speeds, but diminish write speeds
Indexes have to be updated Always a compromise between read and
write performance
![Page 25: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/25.jpg)
SQL Index WizardsSQL Index Wizards
Help analyze database usage and suggest useful indexes that can be added
Also suggests indexes that can be removed
Ideal when used with production-quality traffic
![Page 26: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/26.jpg)
Getting SQL TrafficGetting SQL Traffic
SQL Profiler lets you capture traffic to a file or database
Run Profiler, and capture to, a different machine than the one you are profiling
Great way to troubleshoot and to gather “real” traffic for tuning wizards
![Page 27: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/27.jpg)
Understanding Query Execution Understanding Query Execution PlansPlans
A plan is generated by the Query Optimizer and is a game plan for how to conduct the query
Specifies what indexes will be used, etc Can be viewed graphically or as XML;
XML plans can be saved and re-used (bad idea)
![Page 28: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/28.jpg)
Hints and Reused PlansHints and Reused Plans
SQL will cache execution plans for a short time and re-use them
But the condition of the database is always changing – a good plan today may be a bad plan tomorrow
Applying manual “hints” or forcing plan re-use often results in good performance short-term, worse long-term
![Page 29: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/29.jpg)
High Availability OptionsHigh Availability Options
Windows Clustering Database Mirroring (w/Witness) Transaction Log Shipping
![Page 30: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/30.jpg)
InstancesInstances
SQL is designed to run multiple copies of itself in parallel
Called instances Each instance is a complete install of
the product One default instance, multiple named
instances SQL Express installs a named instance
by default
![Page 31: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/31.jpg)
SecuritySecurity
Security is configured first as the instance level: Windows or Mixed authentication (determines type of logins allowed)
Logins grant access to the server Logins map to in-database users, which
grant access to databases
![Page 32: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/32.jpg)
PermissionsPermissions
Permissions assigned via membership in roles (in-SQL groups, basically) or via direct permissions
Each DB object is owned by a particular user
Permissions chaining says SQL only checks permissions on an owner change
![Page 33: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/33.jpg)
More FunMore Fun
Let’s look at database options and discuss what they do
Discuss user databases in SQL Express Discuss attaching/detaching databases Discuss misc. SQL Server components:
Reporting, Integration, Analysis
![Page 34: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/34.jpg)
More ResourcesMore Resources
Drop off a business card (or your e-mail address) and Greg Shields and I will send you our decks and other class materials (scripts, samples, etc)
Visit http://ConcentratedTech.com for free, daily technical articles, Q&A, step-by-step guides, and much more
Want my “USB Go Pack?” It’s a 4GB USB key stuffed with video clips, white papers, step-by-step guides, articles, and much more – available only here for $60.
![Page 35: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/35.jpg)
THE SQL LANGUAGETHE SQL LANGUAGEPART 2
![Page 36: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/36.jpg)
How WeHow We’’ll Proceedll Proceed
Most of this will be done as demos. I’ll make the queries available as
downloads for you I’ll also detach the sample database and
include that for you– Note: Most of the sample data will be created
on-the-fly – makes it easier to see what data is coming from where
Slide at the end will have the address
![Page 37: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/37.jpg)
Major Language ElementsMajor Language Elements
Queries SELECT: Get Data INSERT: Add Data UPDATE: Change Data DELETE: Remove
Data
Clauses WHERE ORDER BY TOP Aggregate
expressions GROUP BY / HAVING UNION JOIN
![Page 38: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/38.jpg)
Thank You!Thank You!
Please feel free to pick up a card if you’d like copies of my session materials
I’ll be happy to take any last questions while I pack up
Please complete and submit an evaluation form for this and every session you attend!
![Page 39: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/39.jpg)
![Page 40: Supporting SQLserver](https://reader033.vdocument.in/reader033/viewer/2022061205/5480b25cb4af9f9e598b481a/html5/thumbnails/40.jpg)
This slide deck was used in one of our many conference presentations. We hope you enjoy it, and invite you to use it
within your own organization however you like.
For more information on our company, including information on private classes and upcoming conference appearances, please
visit our Web site, www.ConcentratedTech.com.
For links to newly-posted decks, follow us on Twitter:@concentrateddon or @concentratdgreg
This work is copyright ©Concentrated Technology, LLC