KEMBAR78
Supporting SQLserver | PPT
Supporting SQL Server – When You ’d Really Rather Not Don Jones ConcentratedTech.com Pre-requisites for this presentation:  1) Strong understanding of basic Windows administration Level:  Advanced
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
About 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
About 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
About 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
SUPPORTING SQL SERVER Part 1
How 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
Physical 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
Filestreams 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
Querying 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)
Changing 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
Committing 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
Recovery 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”
Backup 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
Backup 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
Tips 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
Performance 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
Indexes 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
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
Index 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
Index 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
Non-Covering Index SELECT Name,ID FROM Users WHERE Name LIKE  ‘D%’ CI NCI ID Name 4 Erin 5 Don 6 Dave Dave Don Erin
Covering Index SELECT Name FROM Users WHERE Name LIKE  ‘D%’ CI NCI ID Name 4 Erin 5 Don 6 Dave Dave Don Erin
Index Downsides Indexes improve lookup speeds, but diminish write speeds Indexes have to be updated Always a compromise between read and write performance
SQL 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
Getting 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
Understanding Query Execution Plans 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)
Hints 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
High Availability Options Windows Clustering Database Mirroring (w/Witness) Transaction Log Shipping
Instances 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
Security 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
Permissions 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
More 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
More 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.
THE SQL LANGUAGE PART 2
How We ’ll 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
Major 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
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!
 
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

Supporting SQLserver

  • 1.
    Supporting SQL Server– When You ’d Really Rather Not Don Jones ConcentratedTech.com Pre-requisites for this presentation: 1) Strong understanding of basic Windows administration Level: Advanced
  • 2.
    This slide deckwas 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
  • 3.
    About the InstructorDon 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
  • 4.
    About this SessionPrimarily 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
  • 5.
    About You AWindows 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
  • 6.
  • 7.
    How SQL ServerWorks 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
  • 8.
    Physical Storage SQLstores 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
  • 9.
    Filestreams New inSQL2008: 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
  • 10.
    Querying Data SQLServer 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)
  • 11.
    Changing Data SQLServer 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
  • 12.
    Committing Data WhenSQL writes affected pages back to disk, it “marks” them as “committed” in the log It does not clear the from the log
  • 13.
    Recovery Mode SQLServer 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”
  • 14.
    Backup Model FullBackup: 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
  • 15.
    Backup 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
  • 16.
    Tips Keep logson 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
  • 17.
    Performance When newobjects (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
  • 18.
    Indexes Help SQLServer 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
  • 19.
    Index Fragmentation (PageSplits) 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
  • 20.
    Index Maintenance Periodicallyrebuild/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
  • 21.
    Index Tricks Anindex 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
  • 22.
    Non-Covering Index SELECTName,ID FROM Users WHERE Name LIKE ‘D%’ CI NCI ID Name 4 Erin 5 Don 6 Dave Dave Don Erin
  • 23.
    Covering Index SELECTName FROM Users WHERE Name LIKE ‘D%’ CI NCI ID Name 4 Erin 5 Don 6 Dave Dave Don Erin
  • 24.
    Index Downsides Indexesimprove lookup speeds, but diminish write speeds Indexes have to be updated Always a compromise between read and write performance
  • 25.
    SQL Index WizardsHelp 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
  • 26.
    Getting SQL TrafficSQL 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
  • 27.
    Understanding Query ExecutionPlans 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)
  • 28.
    Hints and ReusedPlans 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
  • 29.
    High Availability OptionsWindows Clustering Database Mirroring (w/Witness) Transaction Log Shipping
  • 30.
    Instances SQL isdesigned 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
  • 31.
    Security Security isconfigured 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
  • 32.
    Permissions Permissions assignedvia 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
  • 33.
    More 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
  • 34.
    More Resources Dropoff 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.
  • 35.
  • 36.
    How We ’llProceed 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
  • 37.
    Major Language ElementsQueries SELECT: Get Data INSERT: Add Data UPDATE: Change Data DELETE: Remove Data Clauses WHERE ORDER BY TOP Aggregate expressions GROUP BY / HAVING UNION JOIN
  • 38.
    Thank You! Pleasefeel 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!
  • 39.
  • 40.
    This slide deckwas 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

Editor's Notes

  • #2 MGB 2003 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #5 MGB 2003 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
  • #39 MGB 2003 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.