Database Administration (SQL Server).pptx

download Database Administration (SQL Server).pptx

of 43

Transcript of Database Administration (SQL Server).pptx

  • 8/9/2019 Database Administration (SQL Server).pptx

    1/43

    DatabaseAdministration

  • 8/9/2019 Database Administration (SQL Server).pptx

    2/43

    Topics

    Database Files and Logs

    Database Administration Basics

    Creating Databases

    Altering Databases and Their Options

    Managing Database and Log Size

    Manipulating Databases

  • 8/9/2019 Database Administration (SQL Server).pptx

    3/43

    Database Files and

    Logs

    MS SQL Server

    Database a collection o! data and theob"ects that represent and interact #ith thatdata

    Tables$ vie#s$ stored procedures$ triggers$

    and constraints are t%pical database ob"ects A single database server instance can have up

    to &'$()( databases$ and each database canhave more than ' billion ob"ects*

  • 8/9/2019 Database Administration (SQL Server).pptx

    4/43

    Transaction Logs

    histor% o! modi!ications to the database$ and

    SQL Server uses it to ensure that a databasehas integrit%

    All changes to the database are !irst #rittento the transaction log and then applied to the

    database +! the database update is success!ul$ the

    transaction is completed and recorded assuccess!ul

    +! the database update !ails$ SQL Serveruses the transaction log to restore thedatabase to its original state*

    t#ophase

    commit

    enables SQL Server to restore a databaseautomaticall% in case o! po#er !ailure$ server

    outage$ or other problems that might occur #hen%ou enter a transaction*

  • 8/9/2019 Database Administration (SQL Server).pptx

    5/43

    Database Files

    Primary data files

    ,ver% database has one primar% data !ile* A primar% data

    !ile stores data and maintains records o! other !iles used ina database* B% de!ault$ primar% data !iles end #ith the*md! e-tension*

    Secondary data files

    These !iles store additional data !or a database* Althoughnot all databases have secondar% data !iles$ a singledatabase can have multiple secondar% data !iles* B%de!ault$ these !iles end #ith the *nd! e-tension*

    Transaction log files

    ,ver% database has at least one transaction log !ile* This!ile contains in!ormation necessar% to restore thedatabase* B% de!ault$ log !iles end #ith the *ld! e-tension*

  • 8/9/2019 Database Administration (SQL Server).pptx

    6/43

    DatabaseAdministration Basics

    .ou can use SQL Server Management

    Studio to carr% out tas/s such as the!ollo#ing0

    1ie#ing database in!ormation Chec/ing user and s%stem databases ,-amining database ob"ects

  • 8/9/2019 Database Administration (SQL Server).pptx

    7/43

    1ie#ing Database+n!ormation

    SQL Server organizes

    in!ormation using a topdo#nhierarch% that starts at thehighest level #ith server groups

    and then moves do#n toservers$ databases$ schemas$and ob"ects

  • 8/9/2019 Database Administration (SQL Server).pptx

    8/43Database Properties

    2rovides general database in!ormation$ such as status$ o#ner$date created$ size$and space available* This page also details the last bac/up date and collationsetting*

    General

    2rovides details on the data and log !iles associated #ith the database* +! thedatabase has been con!igured !or !ullte-t search$ the 3se FullTe-t +nde-ingchec/ bo- is selected* Catalog !iles associated #ith the database are not listed*

    Files

    Lists the !ilegroups associated #ith the database and allo#s %ou to add or remove!ilegroups*

    Filegroups

    2rovides controls !or vie#ing and managing standard database options andsettings*

    Options

    2rovides controls !or vie#ing and managing changetrac/ing settings*

    Change Tracing

  • 8/9/2019 Database Administration (SQL Server).pptx

    9/43

    Lists users or roles that have speci!ic permissions allo#ed or denied inthe database* Also allo#s %ou to set database permissions !or users or

    roles*

    Permissions

    2rovides controls !or vie#ing and managing e-tended databaseproperties*

    !"tended Properties

    2rovides controls !or vie#ing and managing database mirroring settings*

    #irroring

    Details the current log shipping con!iguration 4i! an%5 and allo#s %ou tomanage log shipping*

    Transaction Log Shipping

  • 8/9/2019 Database Administration (SQL Server).pptx

    10/43

    1ie#ing Database+n!ormation 3sing TSQL

    TSQL is an enhanced version o! the standard structured 6uer%

    language that SQL Server uses

    +n SQL Server Management Studio$ access the Quer% vie# b%rightclic/ing the name o! a server %ou have connected toalread% in the Ob"ect ,-plorer vie# and selecting 7e# Quer%*

    sp8helpdb 9dbname:

    go

  • 8/9/2019 Database Administration (SQL Server).pptx

    11/43

    Checing the SystemDatabases

    *S%stem databases are critical to the proper

    operation o! SQL Server$ and an important

    aspect o! the administration process is bac/ingup and maintaining these databases*

  • 8/9/2019 Database Administration (SQL Server).pptx

    12/43

  • 8/9/2019 Database Administration (SQL Server).pptx

    13/43

    ,-amining Database

    Ob"ects

    Certi!icates

    Constraints

    De!aults

    +nde-es

    ;e%s

    Stored procedures and e-tended stored procedures

    Tables

  • 8/9/2019 Database Administration (SQL Server).pptx

    14/43

    Database Diagrams Contains visual diagrams o! a database and thein!ormation it contains* 3se Database Designer to create and manage

    diagrams*

    Tables Contains s%stem and user tables* S%stem tables are used !or man%purposes$ including database mail$ database maintenance plans$replication$ bac/up and restore$ and log shipping* S%stem tables should notbe modi!ied directl%*

    $ie%s Contains s%stem and user vie#s* Standard vie#s combine data !romone or more tables to ma/e #or/ing #ith the data easier* +nde-ed vie#shave uni6ue clustered inde-es to improve 6uer% per!ormance* 2artitionedvie#s "oin horizontall% partitioned data !rom tables on one or more servers*

    Synonyms Contains s%non%ms$ #hich are alternate names !or schemascoped ob"ects* Applications can use s%non%ms to re!er to ob"ects in thedatabase abstractl%* .ou can then change the underl%ing name o! theob"ect #ithout having to modi!% the application programming*

  • 8/9/2019 Database Administration (SQL Server).pptx

    15/43

    Programmability Contains nodes used to represent most programmableob"ect t%pes and subt%pes$ including stored procedures$ !unctions$triggers$ assemblies$ data t%pes$ rules$ and de!aults* This node also

    contains plan guides*

    Ser&ice Broer Contains Service Bro/er

  • 8/9/2019 Database Administration (SQL Server).pptx

    16/43

    Plan Guides' BroerPriorities ( Full )te"t

    stoplists

    Bro/er 2riorities

    Bro/er priorities de!ine a priorit% level andthe set o! criteria !or determining #hichService Bro/er conversations to assign thepriorit% level

    Servicer Bro/er assigns the priorit% level toan% conversation endpoint that uses the samecombination o! contracts and services thatare speci!ied in the conversation priorit%*

  • 8/9/2019 Database Administration (SQL Server).pptx

    17/43

    Plan Guides

    *.ou can create plan guides to help optimize

    6ueries that are not per!orming as e-pected*

    *%ou can speci!% the TSQL statement that %ou#ant to be optimized and either an O2T+O7

    clause that contains the 6uer% hints %ou #ant

    to use or a speci!ic 6uer% plan %ou #ant to use

    to optimize the 6uer%

  • 8/9/2019 Database Administration (SQL Server).pptx

    18/43

    * Types of Plan Guides

  • 8/9/2019 Database Administration (SQL Server).pptx

    19/43

    Full+te"t stoplists

  • 8/9/2019 Database Administration (SQL Server).pptx

    20/43

    Creating Databases

  • 8/9/2019 Database Administration (SQL Server).pptx

    21/43

    Creating Databases

  • 8/9/2019 Database Administration (SQL Server).pptx

    22/43

    Creating Databases

  • 8/9/2019 Database Administration (SQL Server).pptx

    23/43

    Creating Databases

    *=indo#s collation names have t#o

    components0 a collation designator and a

    comparison st%le*collation designator speci!ies the alphabet or

    language #hose sorting rules are applied #ith

    dictionar% sorting and the code page to use

    #hen storing non3nicode character data

  • 8/9/2019 Database Administration (SQL Server).pptx

    24/43

  • 8/9/2019 Database Administration (SQL Server).pptx

    25/43

    Creating Databaseusing T+S,L

  • 8/9/2019 Database Administration (SQL Server).pptx

    26/43

    *3S, MAST,>

    *?O

    *C>,AT, DATABAS, Sample

    *O7

    *2>+MA>.

    *4 7AM, @ Sample$

    *F+L,7AM, @ c0datasampledat*md!$

    *S+, @ EEMB$

    *MAS+, @ 37L+M+T,D$

    *F+L,?>O=TG @ EH5$

    *4 7AM, @ Sample'$

    *F+L,7AM, @ c0datasampledat'*nd!$

    *S+, @ EEMB$

    *MAS+, @ 37L+M+T,D$

    *F+L,?>O=TG @ EH5

    *LO? O7

    *4 7AM, @ SampleLog$*F+L,7AM, @ c0datasamplelog*ld!$

    *S+, @ &MB$

    *MAS+, @ 37L+M+T,D$

    *F+L,?>O=TG @ IMB5

    *?O

  • 8/9/2019 Database Administration (SQL Server).pptx

    27/43

    Altering Databases

  • 8/9/2019 Database Administration (SQL Server).pptx

    28/43

  • 8/9/2019 Database Administration (SQL Server).pptx

    29/43

    Con!iguring AutomaticOptions

  • 8/9/2019 Database Administration (SQL Server).pptx

    30/43

    Con!iguring AutomaticOptions

  • 8/9/2019 Database Administration (SQL Server).pptx

    31/43

    Con!iguring AutomaticOptions

    Auto Shrin -auto.shrin/

    =hen this option is set to T>3,$ dataand log !iles are reduced in size andcompacted automaticall%* =henrecords are deleted or purged$ SQLServer automaticall% reduces the sizeo! data or log !iles or both !ile t%pes*

  • 8/9/2019 Database Administration (SQL Server).pptx

    32/43

    Con!iguring AutomaticOptions

    Auto 0pdate Statistics

    -auto.update.statistics/

    =hen this option is set to T>3,4the de!ault5$ e-isting statistics

    are updated automaticall% i! datain the related tables changes*

  • 8/9/2019 Database Administration (SQL Server).pptx

    33/43

    Con!iguring AutomaticOptions

    Auto 0pdate Statistics Asynchronously

    -auto.update.statistics.async/ =hen this option is set to T>3,$

    6ueries that initiate an automaticupdate o! outo!date statistics do not

    #ait !or the statistics to be updatedbe!ore compiling*

  • 8/9/2019 Database Administration (SQL Server).pptx

    34/43

    Configuring

    Parameteri1ation

    SQL Server can use parameters in TSQL statementsto increase the abilit% o! the relational engine tomatch ne# SQL statements #ith e-isting$ previousl%compiled e-ecution plans*

    2arameterization Option

    S+M2L, SQL Server parameterizes ver% !e# classes o!

    6ueries and disables !orced parameterization* FO>C,D

    an% literal value that appears in a S,L,CT$+7S,>T$ 32DAT,$ or D,L,T, statementsubmitted in an% !orm is converted to a

    parameter during 6uer% compilation*

  • 8/9/2019 Database Administration (SQL Server).pptx

    35/43

    Configuring CursorOptions

    Cursors are used #ith stored

    procedures$ #ith triggers$and in batch scripts to ma/ethe contents o! a result set

    available to other statements

  • 8/9/2019 Database Administration (SQL Server).pptx

    36/43

    Configuring Cursor

    Options

    Close Cursor On Commit !nabled-cursor.close.on.commit/

    =hen this option is set to T>3,$ open cursors are closedautomaticall% #hen a transaction is committed or rolled bac/*

    Default Cursor -cursor.default/

    LOCAL$ cursors are created #ith local scope unless other#ise speci!ied*

    As a result$ the cursor name is valid onl% #ithin this scope* ?LOBAL$

    cursors not e-plicitl% set to LOCAL are created #ith a global scopeand can be re!erenced in an% stored procedure$ batch$ or triggerthat the connection e-ecutes*

  • 8/9/2019 Database Administration (SQL Server).pptx

    37/43

    Controlling 3ser Access

    and Database State

    +n SQL Server ManagementStudio$ %ou can control thegeneral state o! the database$including #hether the database

    is readonl% or read#rite and#ho has access to thedatabase*

  • 8/9/2019 Database Administration (SQL Server).pptx

    38/43

    >,AD8O7L.$

    %ou can read data but not modi!% it* .ou use this option to prevent users !romchanging data and modi!%ing database con!iguration settings*

    >,AD8=>+T,$ 7ormal Mode$ #hich allo#s the database to be read and modi!ied*

    S+7?L,83S,>$

    onl% the database o#ner can access the database* .ou use this option #hen%ou are modi!%ing a database and #ant to bloc/ access to it temporaril%*

    >,ST>+CT,D83S,>$

    onl% members o! the db8o#ner$ dbcreator$ or s%sadmin roles can use thedatabase

    M3LT+83S,>$

    all users #ith the appropriate permissions to connect to the database arepermitted to use it*

    Database State

  • 8/9/2019 Database Administration (SQL Server).pptx

    39/43

    Con!iguring >ecover%$ Logging$ and Dis/ +JO ,rror

    Chec/ing Options

    +n SQL Server Management Studio$ %oumanage recover% settings b% using the>ecover% Model and 2age 1eri!% settingson the Options page

    +n TSQL$ %ou manage these options b%

    using the ALT,> DATABAS, S,T >,CO1,>.and ALT,> DATABAS, S,T 2A?,81,>+F.commands

  • 8/9/2019 Database Administration (SQL Server).pptx

    40/43

    Con!iguring >ecover%$ Logging$ and Dis/ +JO ,rror

    Chec/ing Options

    F0LL =hen recover% is set to F3LL$ transactions are !ull% loggedand the database can be recovered to the point o! !ailure or to aspeci!ic point in time using the transaction logs

    B0L2.LOGG!D =hen recover% is set to B3L;8LO??,D$ certainSQL commands are not logged in the transaction log* Thesecommands include using S,L,CT +7TO and B3L; +7S,>T #ith apermanent table$ running !ast bul/ cop%$ using 32DAT,T,T or

    =>+T,T,T #ithout logging$ and using a table load*

    S3#PL! =hen recover% is set to S+M2L, 4previousl% managed usingtrunc*log on ch/pt5$ the transaction log can be truncatedautomaticall%* This setting allo#s the log to be cleared a!ter

    transactions have been committed*

  • 8/9/2019 Database Administration (SQL Server).pptx

    41/43

    Dis 34O !rrors

    Dis/ +JO errors can causedatabase corruption problemsand are usuall% the result o!po#er !ailures or dis/ hard#are

    !ailures that occur at the timea page is #ritten to dis/*

  • 8/9/2019 Database Administration (SQL Server).pptx

    42/43

    Dis 34O !rror

    three page veri!ication options to help identi!%incomplete +JO transactions caused b% dis/ +JOerrors0

    C5!C2S0# are used to !ind incomplete +JO transactionscaused b% dis/ +JO errors* The chec/sum is computed overthe contents o! the entire page and stored in the pageheader #hen a page is #ritten to dis/*

    TO67.PAG!.D!T!CT3O7' a bit is reversed !or each I'b%te sector in an K;B database page #hen the page is#ritten to dis/

    7O7!$ !uture data page #rites #ill not contain achec/sum or torn page bit$ and pages #ill not be veri!iedat read time$ even previousl% #ritten pages that contain a

    chec/sum or torn page bit*

  • 8/9/2019 Database Administration (SQL Server).pptx

    43/43