SQL Server 2008 Tutorial

Embed Size (px)

Citation preview

  • 7/26/2019 SQL Server 2008 Tutorial

    1/38

    SQL Server

    SQL Server is an enterprise database management system (DBMS) from Microsoft. It is used by

    thousands of companies wordwide and is used by thousands! if not miions! of websites around the

    word.

    SQL Server (2014) Tutorial

    "his tutoria e#pains what SQL Server $%&' is and

    how to use it. ou shoud have a basic nowedge

    of reationa database management systems and

    how they wor. Based on SQL Server $%&'.

    Basic Database Tutorial

    If you don*t fee +uite ready to ,ump into the SQL

    Server tutoria or the SQL tutoria! start here. "his

    tutoria wi e#pain what a database management

    system (DBMS) is! the typica features that mae

    up a DBMS! and how they are generay used.

    SQL Server (2008) Tutorial

    Simiar to the SQL Server $%&' tutoria but based

    on SQL Server $%%-.

    SQL Tutorial

    If you*ve competed the SQL Server tutoria! try

    this one ne#t. "his tutoria covers SQL (Structured

    Query Language)! and is essentia if you need to

    deveop database driven websites.

    SQL Server 2000 Tutorial

    ery simiar to the SQL Server $%%- and $%&'

    tutorias! e#cept this one is was written a reay

    ong time ago...

    Microsoft Access Tutorial

    "his tutoria e#pains what Microsoft /ccess is and

    how to use it. ou don*t need to do the SQL

    tutoria first! however! you shoud have a basic

    nowedge of reationa database management

    systems and how they wor.

    SQL Server 2008 Tutorial

    "his SQL Server tutoria is for anyone who wants to earn how to use SQL Server $%%-. It assumes abasic understanding of databases and how they wor.

    If you don*t currenty have an understanding of how databases wor! start with the basic database

    tutoriafirst. "hat tutoria covers the basic concepts of databases! so the e#ampes in this tutoria wi

    mae more sense once you return here.

    "o get the most out of this tutoria! you shoud have a copy of SQL Server instaed on your computer! so

    that you can go through the e#ampes yoursef. "he e#ampes in this tutoria are a done using the free

    version of SQL Server 0 SQL Server $%%- 1#press. ou can downoad SQL Server $%%- 1#press from the

    Microsoft website (we* get to that in a minute).

    If you don*t currenty have SQL Server yet! that*s 23. "he tutoria is straight forward and contains penty

    of screenshots.

    http://www.quackit.com/sql_server/tutorial/http://www.quackit.com/database/tutorial/http://www.quackit.com/sql_server/sql_server_2008/tutorial/http://www.quackit.com/sql/tutorial/index.cfmhttp://www.quackit.com/sql_server/sql_server_2000/tutorial/http://www.quackit.com/microsoft_access/tutorial/http://www.quackit.com/database/tutorial/http://www.quackit.com/database/tutorial/http://www.quackit.com/database/tutorial/http://www.quackit.com/sql_server/sql_server_2008/tutorial/http://www.quackit.com/sql/tutorial/index.cfmhttp://www.quackit.com/sql_server/sql_server_2000/tutorial/http://www.quackit.com/microsoft_access/tutorial/http://www.quackit.com/database/tutorial/http://www.quackit.com/database/tutorial/http://www.quackit.com/sql_server/tutorial/
  • 7/26/2019 SQL Server 2008 Tutorial

    2/38

    Table of Contents

    "his tutoria consists of the foowing essons4

    &. /bout SQL Server

    $. SQL Server 1ditions

    5. SQL Server 0 Management Studio

    '. SQL Server 0 6reate a Database

    7. SQL Server 0 6reate a "abe

    8. SQL Server 0 /dding Data

    9. SQL Server 0 Query Designer

    -. SQL Server iews

    :. SQL Server Stored ;rocedures

    &%.

  • 7/26/2019 SQL Server 2008 Tutorial

    3/38

    Aeneray! it*s the appication that provides the functionaity to these visitors. It is the database that

    stores the data and maes it avaiabe. aving said that! SQL Server does incude some usefu features

    that can assist the appication in providing its functionaity.

    SQL Server 1ditions

    SQL Server comes in many editions. Some are paid versions others are free. "he e#ampes in this

    tutoria were done using the free 1#press version of SQL Server.

    "he ne#t essondiscusses the various editions of SQL Server $%%-.

    SQL Server 2008 !itions

    If you are serious about instaing (or upgrading) SQL Server! this page provides a +uic overview of

    your options.

    SQL Server $%%- comes in many different editions. "he edition you choose wi depend on your

    re+uirements. If you are ooing for a free database management system! you wi need to choose one

    of the Expresseditions or the Compactedition. ou coud aso try the Evaluationedition! which aows

    you to tria SQL Server $%%- for &-% days.

    T"e !itions

    ere are the different editions avaiabe for SQL Server $%%-.

    nter#rise !itionData management and business inteigence patform providing enterprise cass scaabiity! high

    avaiabiity! and security for running business0critica appications

    Stan!ar! !ition

    Data management and business inteigence patform providing ease of use and manageabiity

    for running departmenta appications

    $or%&rou# !ition

    Data management and reporting patform providing secure! remote synchroniCation! and

    management capabiities for running branch appications

    Develo#er !ition

    May be instaed and used by one user to design! deveop! test! and demonstrate your programs

    on as many systems as needed

    $eb !ition

    / ow0"62! scaabe! and manageabe database option for web hosters and end customers

    ooing to depoy pubicy facing web appications and services

    '#ress !ition

    / free edition of SQL Server idea for earning and buiding destop and sma server appications

    and for redistribution by ISs

    http://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_server_editions.cfmhttp://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_server_editions.cfmhttp://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_server_editions.cfm
  • 7/26/2019 SQL Server 2008 Tutorial

    4/38

    Co#act !ition

    / free! SQL Server embedded database idea for buiding stand0aone and occasionay

    connected appications for mobie devices! destops! and web cients

    valuation !ition

    "his edition may be instaed for demonstration and evauation purposes unti an e#pirationperiod of &-% days.

    SQL Server !ition in t"is Tutorial

    "he e#ampes in this tutoria were made using the (free) 1#press edition of SQL Server $%%-. "o be

    more precise! it is SQL Server $%%- 1#press with /dvanced Services.

    SQL Server $%%- 1#press with /dvanced Services incudes the foowing features4

    SQL Server database engine 0 create! store! update and retrieve your data

    SQL Server Management Studio Basic 0 visua database management too for creating! editing

    and managing databases

    ?u0te#t Search 0 powerfu! high0speed engine for searching te#t0intensive data

    =eporting Services 0 integrated report creation and design environment to create reports

    "he 1#press edition aso comes as SQL Server 2008 Express with Tools! which ony incudes the SQL

    Server database engine and the SQL Server Management Studio Basic! and SQL Server 2008 Express

    (Runtime Onlywhich doesn*t incude the SQL Server Management Studio.

    @hie the free version of SQL Server does have its imitations! it is a good start for those starting out

    with SQL Server.

    ou can downoad SQL Server $%%- 1#pressfrom Microsoft*s website.

    SQL Server Mana&eent Stu!io (SSMS)

    SQL Server Management Studio (SSMS) is the main administration consoe for SQL Server.

    SSMS enabes you to create database ob,ects (such as databases! tabes! views etc)! view the data

    within your database! you can configure user accounts! transfer data between databases! and more.

    ere*s what SQL Server Management Studio oos ie when you first open it up4

    http://www.microsoft.com/downloads/details.aspx?FamilyId=B5D1B8C3-FDA5-4508-B0D0-1311D670E336&displaylang=enhttp://www.microsoft.com/express/sql/download/http://www.microsoft.com/downloads/details.aspx?FamilyId=B5D1B8C3-FDA5-4508-B0D0-1311D670E336&displaylang=enhttp://www.microsoft.com/express/sql/download/
  • 7/26/2019 SQL Server 2008 Tutorial

    5/38

    "he eft pane contains the 2b,ect 1#porer. "he 2b,ect 1#porer provides navigation to databases! server

    ob,ects (such as triggers)! og fies! and more.

    "he right pane aows you to write +ueries against the database and view the resuts. In this screenshot

    I have opened a ban +uery by cicing the Eew Query button. ou can aso bring up other windows!

    such as the ;roperties window.

    Eote that I have minimiCed the siCe of the window for this screenshot. 2nce ma#imiCed! you have much

    more room to pay with.

    ou can use SQL Server Management Studio to create as many databases as you ie. ou can aso

    connect to as many databases on as many servers as you ie.

    Most of the tass performed with SQL Server Management Studio are initiated either from the top menu!

    or by right0cicing on an iconFob,ect.

    "hroughout most of this tutoria! we* be ooing at the various things you can do via SQL Server

    Management Studio.

    SQL Server Create a Database

  • 7/26/2019 SQL Server 2008 Tutorial

    6/38

    2ne of the first things we shoud oo at with SQL ServerFManagement Studio is how to create a

    database. /fter a! most of the tass you perform with SQL Server wi evove around one or more

    databases.

    S*ste Databases

    If you*ve ony ,ust instaed SQL Server! you might notice that some databases have aready been

    created. "hese are system databases.

    Databas

    e

    T*#e Descri#tion

    master System

    databas

    e

    Stores system eve information such as user accounts! configuration settings!

    and info on a other databases.

    mode System

    database

    "his database is used as a tempate for a other databases that are created.

    msdb System

    databas

    e

  • 7/26/2019 SQL Server 2008 Tutorial

    7/38

    &. =ight cic on the Databases icon and seect Eew Database...4

  • 7/26/2019 SQL Server 2008 Tutorial

    8/38

    $. Eame your database and cic 234

    -our +e, Database

    ou wi now notice your new database appears under the Databases section of SQL Server

    Management Studio.

    our new database is based on the Mode database. "he Mode database is a system database which is

    used as a tempate whenever a new database is created. If you use the eft pane to navigate to your

    database and e#pand the tree! you wi notice that your database aready contains a number of ob,ects.

    ?or e#ampe! it aready contains system functions! system views! system stored procedures! and

    (hidden) system tabes. "hese are system ob,ects which provide information about the database.

  • 7/26/2019 SQL Server 2008 Tutorial

    9/38

    .t"er .#tions

    @e have ,ust created a database using the defaut options. @hen we created the database! a Data ?ie

    and a "ransaction Log were created. "hey were created in the defaut ocation for our server.

    If we*d wanted to! we coud have specified a different ocation for these fies. @e aso coud have

    changed specifications on whether to aow the fie to grow automaticay (as it stores more and more

    data)! and if so! how that growth shoud be managed. @e coud have done that at step $. But a is not

    ost. @e can sti do it now that we*ve created the database. @e can do it via the ;roperties diaog bo#.

    "o view or change the database properties! simpy right cic on the database and seect ;roperties4

  • 7/26/2019 SQL Server 2008 Tutorial

    10/38

    "he ;roperties diaog contains a arge number of options for changing the configuration of your

    database. ?or now! we can eave everything at its defaut setting.

  • 7/26/2019 SQL Server 2008 Tutorial

    11/38

    SQL Server Create a Table

    "his esson demonstrates how to create a tabe in a SQL Server database using SQL Server Management

    Studio (SSMS).

  • 7/26/2019 SQL Server 2008 Tutorial

    12/38

    &. 1nsuring you have the right database e#panded! right cic on the "abes icon and seect Eew

    "abe...4

    $. @hie you have this screen open! do the foowing4

    a.

  • 7/26/2019 SQL Server 2008 Tutorial

    13/38

    @hat we are doing at this stage! is creating the coumn names! specifying the type of data that

    can be entered into them! and setting defaut vaues. =estricting the data type for each coumn

    is very important and heps maintain data integrity. ?or e#ampe! it can prevent us from

    accidentay entering an emai address into a fied for storing the current date.

    5. Save the tabe by seecting #ile $ Save Ta%le&'4

  • 7/26/2019 SQL Server 2008 Tutorial

    14/38

    '. @hen prompted! name your tabe4

    -our +e, Table

    Eow that you*ve created a new tabe! it wi appear under your database in the "abes section.

    SQL Server A!!in& Data

    In the previous esson! we created a new tabe in our database. @e now have a database tabe! coumns

    and a! but with no data.

    !itin& Table /o,s

  • 7/26/2019 SQL Server 2008 Tutorial

    15/38

    @e can use the 1dit "op $%% =ows option to add data to our tabe.

    &. "o use this option! right cic on the tabe you wish to open! and seect 1dit "op $%% =ows4

    $. ou can now start entering the data directy into your tabe.

    Eote that you don*t need to enter data into the IndividuaId and Date6reated coumns. "his is

    because the they wi be popuated automaticay (remember! we set IndividuaId to Is Identity

    and Date6reated to (AetDate()))

    Disa!vanta&es of nterin& Data Directl* to *our Table

    "he above method is fine if you ony have a sma amount of data to enter or update. If you have a ot of

    data to enter! this coud become very tedious. /so! if you have mutipe environments (for e#ampe! a

    deveopment environment! staging environment! and production environment)! with dupicate databases

    configured in each environment! you wi need to re0enter the same data into each environment.

    @hen you*re first earning SQL Server! this may not be a ma,or concern. owever! in an environment

    such as described! entering data directy into the tabe becomes +uite inefficient.

    A Better Met"o! SQL Scri#ts

    In most cases! you wi probaby find it more efficient to write a SQL script.

  • 7/26/2019 SQL Server 2008 Tutorial

    16/38

    can simpy run your script to enter the data. If you have mutipe environments! once again you can run

    your script against each environment.

    2nce you get used to writing and running scripts! you wi probaby find it +uicer than entering data

    directy into the tabe.

    Database Driven $ebsites

    @hen you create a database driven website! you actuay write SQL scripts to insert data into the

    database. ou aso use SQL scripts to read data! update data! and deete data. "hese SQL scripts can be

    paced directy into your website code (;;! 6od?usion etc)! or they can be stored in the database

    as Store" roce"uresor )iews.

    In the ne#t esson! we wi oo at how to write and e#ecute SQL scripts within SQL Server.

    SQL Server SQL Scri#ts

    In the previous esson! we added data to our database tabe using the 1dit "op $%% =ows option. In

    this esson! we wi oo at how to write SQL scripts to update and run +ueries against our database.

    Create a +e, Quer*

    Before we generate our SQL script! we need somewhere to enter it into. "his part is easy. Gust cic the

    Eew Query button4

    / ban! white sheet shoud now appear on the right pane.

    $rite/un -our SQL Scri#t

    ou are now ready to write SQL +ueries against your database. ou can use this interface to create

    database ob,ects (such as databases! tabes! views etc)! insert data into a database tabe! seect data!

    update data! deete data.

    "o run an SQL +uery4

    http://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_scripts.cfmhttp://www.quackit.com/sql_server/sql_server_2008/tutorial/adding_data.cfmhttp://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_scripts.cfmhttp://www.quackit.com/sql_server/sql_server_2008/tutorial/adding_data.cfm
  • 7/26/2019 SQL Server 2008 Tutorial

    17/38

  • 7/26/2019 SQL Server 2008 Tutorial

    18/38

    In the previous esson! we created a SQL script using SQL Server Management Studio (SSMS). In this

    esson! we wi oo at how to write SQL scripts using the graphica +uery designer.

    About T"e Quer* Desi&ner

    "he graphica +uery designer is a graphica user interface that aows you to buid +ueries to run againstyour SQL Server database. "his can be particuary usefu when buiding compe# +ueries that invoves

    many tabes! views etc.

    "he +uery designer can aso be beneficia for those who are earning how to write SQL. "his is because

    you don*t need to remember the SQL synta# in order to write +ueries against your database 0 the +uery

    designer generates the SQL for you.

    Buil!in& -our Queries

    "o buid a +uery with the +uery designer4

    &. Seect Query $ *esi!n Query in E"itor+++4

    http://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_scripts.cfmhttp://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_scripts.cfm
  • 7/26/2019 SQL Server 2008 Tutorial

    19/38

    $. /dd the tabes you want to run the +uery against. In this case! we ony have one tabe to

    choose from.

    5. Seect the coumnFs you want to dispay in your +uery4

  • 7/26/2019 SQL Server 2008 Tutorial

    20/38

    '. 6ic 23

    2nce you*ve ciced 23! you wi find the +uery has been added to your worspace. ou can then run it

    as you woud any other +uery.

    SQL Server ie,s

    In SQL Server! a viewis a pre0written +uery that is stored on the database. / view consists of a S1L16"

    statement! and when you run the view! you see the resuts of it ie you woud when opening a tabe.

    Some peope ie to thin of a view as a virtua tabe. "his is because a view can pu together data from

    mutipe tabes! as we as aggregate data! and present it as though it is a singe tabe.

    Benefits of ie,s

    / view can be usefu when there are mutipe users with different eves of access! who a need to see

    portions of the data in the database (but not necessariy a of the data). iews can do the foowing4

    =estrict access to specific rows in a tabe

    =estrict access to specific coumns in a tabe

    Goin coumns from mutipe tabes and present them as though they are part of a singe tabe

    ;resent aggregate information (such as the resuts of the 62

  • 7/26/2019 SQL Server 2008 Tutorial

    21/38

    Creatin& a ie,

    ou create a view by using the 6=1/"1 I1@ statement! foowed by the S1L16" statement.

    6opy to 6ipboard

    CREATE VIEW ViewNameAS

    SELECT ...

    1#ampe4

    6opy to 6ipboard

    CREATE VIEW "Alphabetical list of products"AS

    SELECT roducts.!Cate#ories.Cate#or$Name

    %R&' Cate#oriesINNER (&IN roducts&N Cate#ories.Cate#or$I)*roducts.Cate#or$I)

    W+ERE ,,,roducts.)isco-ti-ued*/

    Mo!ifin& a ie,

    ou can modify an e#isting view by using using /L"1= instead or 6=1/"1.

    1#ampe4

    6opy to 6ipboard

    ALTER VIEW "Alphabetical list of products"AS

    SELECT roducts.!Cate#ories.Cate#or$Name

    %R&' Cate#oriesINNER (&IN roducts&N Cate#ories.Cate#or$I)*roducts.Cate#or$I)W+ERE ,,,roducts.)isco-ti-ued*/

  • 7/26/2019 SQL Server 2008 Tutorial

    22/38

    ou can aso right cic on the view and seect Design.

    /unnin& a ie,

    ou run a view by using a S1L16" statement.

    6opy to 6ipboard

    SELECT T& 0///!

    %R&' 1Ad2e-tureWor3s4//56.1Sales6.12I-di2idualCustomer6

    ou can aso right0cic on the view and seect Seect "op &%%% =ows.

    =unning the above view resuts in this4

    /s you can see! it oos ,ust ie you*ve seected rows from a tabe. "he difference is that! each coumn

    coud potentiay be coming from a different tabe.

    SQL Server Store! roce!ures

    Stored procedures are a powerfu part of SQL Server. "hey can assist programmers and administrators

    greaty in woring with the database configuration and its data.

    / stored procedure is a precompied group of "ransact0SQL statements! and is saved to the database

    (under the Stored ;rocedures node). ;rogrammers and administrators can e#ecute stored procedures

    either from the SQL Server Management Studio or from within an appication as re+uired.

    "ransact0SQL! which is based on SQL (Structured Query Language)! is the programming anguage used

    to interface between appications and their databases. "ransact0SQL is a reativey easy anguage to

    earn and I highy recommend becoming famiiar with it.

    http://www.quackit.com/sql/tutorial/sql_introduction.cfmhttp://www.quackit.com/sql/tutorial/sql_introduction.cfm
  • 7/26/2019 SQL Server 2008 Tutorial

    23/38

    Benefits of Store! roce!ures

    ere are some ey benefits in using stored procedures4

    Benefit '#lanation of benefit

    Moduar

    programming

    ou can write a stored procedure once! then ca it from mutipe paces in your

    appication.

    ;erformance Stored procedures provide faster code e#ecution and reduce networ traffic.

    ?aster e#ecution4 Stored procedures are parsed and optimiCed as soon as they

    are created and the stored procedure is stored in memory. "his means that it

    wi e#ecute a ot faster than sending many ines of SQL code from your

    appication to the SQL Server. Doing that re+uires SQL Server to compie and

    optimCe your SQL code every time it runs.

    =educed networ traffic4 If you send many ines of SQL code over the networ

    to your SQL Server! this wi impact on networ performance. "his is especiay

    true if you have hundreds of ines of SQL code andFor you have ots of activity

    on your appication. =unning the code on the SQL Server (as a stored

    procedure) eiminates the need to send this code over the networ. "he ony

    networ traffic wi be the parameters suppied and the resuts of any +uery.

    Security

  • 7/26/2019 SQL Server 2008 Tutorial

    24/38

    If you need to modify an e#isting stored procedure! you simpy repace the 6=1/"1 with /L"1=.

    6opy to 6ipboard

    ALTER R&CE)7RE '$StoredrocedureAS

    ...

    /unnin& a Store! roce!ure

    ou can run a stored procedure by using E.EC-TEor E.EC. ?or e#ampe! to run the above stored

    procedure! type the foowing4

    6opy to 6ipboard

    E;EC '$Storedrocedure

    If the stored procedure has spaces in its name! encose it between doube +uotes4

    6opy to 6ipboardE;EC "'$ Stored rocedure"

    If your stored procedure accepts any parameters! they are paced after the procedure name4

    6opy to 6ipboard

    E;EC '$Storedrocedure

  • 7/26/2019 SQL Server 2008 Tutorial

    25/38

    5. / diaog wi appear. 1nter your chosen parameter vaues etc4

    '. 6ic 23

    7. SQL Server wi now generate the SQL code and e#ecute the stored procedure4

    araeters

    / parameter is a vaue that your stored procedure uses in order to perform it*s tas. @hen you write a

    stored procedure! you can specify the parameters that need to be suppied from the user. ?or e#ampe! if

    you write a stored procedure to seect the address detais about an individua! your stored procedure

    needs to now which individua to seect. In this case! the user can provide an IndividuaId or

  • 7/26/2019 SQL Server 2008 Tutorial

    26/38

    configure security accounts

    set up ined servers

    create a database maintenance pan

    create fu te#t search cataogs

    configure repication

    set up schedued ,obs

    and much more.

    SQL Server 3ser Lo&ins

    SQL Server aows for the creation of user ogins. 1ach individua who needs access to SQL Server can be

    given their own user account.

    @hen the administrator configures these user ogins! heFshe can assign them to any number of roes

    and schemas! depending on the access that the individua is entited to.

    In this esson! we wi wa through the steps in creating a user ogin.

    To Create a +e, 3ser Lo&in

    &.

  • 7/26/2019 SQL Server 2008 Tutorial

    27/38

    '. 6ic the Server =oes tab if you need to appy any server0wide security privieges.

    7. 6ic the

  • 7/26/2019 SQL Server 2008 Tutorial

    28/38

    SQL Server Server /oles

    @hen creating a new user ogin in SQL Server! you get the option of assigning the ogin one or more

    server roes.

    Server roes (not to be confused with database roes) are avaiabe for various database administration

    tass. Eot everyone shoud be assigned to a server roe. In fact! ony advanced users such as database

    administrators shoud be assigned a server roe.

    Accessin& t"e Server /oles

    "o access the server roes in SQL Server Management Studio! e#pand the Security foder4

  • 7/26/2019 SQL Server 2008 Tutorial

    29/38

    ou view the properties of a server roe by right cicing on it. ou can then add users to the server roe

    by cicing /dd. In the screenshot beow! omer has been added to the securitya"minroe.

    '#lanation of Server /oles

    ere*s an e#panation of the server roes defined in SQL Server $%%- during setup4

    Server /ole Descri#tion

  • 7/26/2019 SQL Server 2008 Tutorial

    30/38

    sysadmin 6an perform any tas in SQL Server.

    serveradmin 6an set server0wide configuration options! can shut down the server.

    setupadmin 6an manage ined servers and startup procedures.

    securityadmin

    6an manage ogins and database permissions! read ogs! change passwords.

    processadmin 6an manage processes running in SQL Server.

    dbcreator 6an create! ater! and drop databases.

    disadmin 6an manage dis fies.

    buadmin 6an e#ecute B

  • 7/26/2019 SQL Server 2008 Tutorial

    31/38

    $. =ight cic on Schemasand seect /ew Schema+++. Lie this4

  • 7/26/2019 SQL Server 2008 Tutorial

    32/38

    5. 6ompete the detais in the eneraltab for the new schema. In this e#ampe! the schema name

    is person and the schema owner is omer.

  • 7/26/2019 SQL Server 2008 Tutorial

    33/38

    '. /dd users to the schema as re+uired and set their permissions4

    7. /dd any e#tended properties (via the Exten"e" roperties ta%)

    8. 6ic O1.

    A!! a Table to t"e +e, Sc"ea

    Eow that we have a new schema! we can add ob,ects such as tabes! views! and stored procedures to it.

    ?or e#ampe! we coud transfer the tabe that we created in the earier esson to the new schema.

    @hen we created that tabe (caed Individua)! it was created in the defaut database schema (dbo).

    @e now this because it appears in our ob,ect browser as dbo.Individua.

    "o transfer the Individua tabe to the person schema4

    &. In 2b,ect 1#porer! right cic on the tabe name and seect Design4

    $. ?rom Design view! press ?' to dispay the ;roperties window.

  • 7/26/2019 SQL Server 2008 Tutorial

    34/38

    5. ?rom the ;roperties window! change the schema to the desired schema4

    '. 6ose Design iew by right cicing the tab and seecting 6ose4

    7. 6ic 23 when prompted to save

    our tabe has now been transferred to the person schema.

    Confir *our C"an&e

    "o confirm the change4

  • 7/26/2019 SQL Server 2008 Tutorial

    35/38

    &. =efresh the 2b,ect Browser view4

    $. ou wi now see that 2b,ect Browser dispays the new schema for the tabe (person.Individua)4

    SQL Server Lin%e! Servers

    If you*ve been navigating around SQL Server Management Studio (SSMS)! you may have come across

    the Lined Servers option.

    "he Lined Servers option aows you to connect to another instance of SQL Server running on a

    different machine! perhaps remotey in a different cityFcountry. "his can be usefu if you need to perform

    distributed +ueries (+uery a remote database). Setting up a ined server is +uite straight forward inSSMS! a you need is detais of the remote server! and the database that you need to +uery.

    Creatin& a Lin%e! Server

    "o create a ined server4

    &. Eavigate to Server O%ects $ Lin3e" Servers

    $. =ight cic on Lin3e" Serversand seect /ew Lin3e" Server+++. Lie this4

    5. 6ompete the detais for the ined server. In this e#ampe! *ata sourcerefers to the name of

    the SQL Server machine (BartsHdatabaseHserver)!Catalo!uerefers to the name of the

    database (BartsHdatabase). ou can aso configure options in the other two tabs depending on

  • 7/26/2019 SQL Server 2008 Tutorial

    36/38

    your re+uirements.

    Distribute! Queries

    2nce you have configured your ined server! you wi be abe to run +ueries etc against it. @hen you run

    a +uery against a ined server! it is referred to as a"istri%ute" 4uery.

    @hen you e#ecute a distributed +uery against a ined server! you must incude a fuy +uaified! four0

    part tabe name for each data source to +uery. "his four0part name shoud be in the

    form lin3e"&server&name+catalo!+schema+o%ect&name.

    ere*s an e#ampe4

    6opy to 6ipboard

    9arts=database=ser2er.9arts=database.erso-.E-em$

    "his e#ampe is based on the ined server e#ampe above. It assumes that the remote database has a

    schema caed ;erson and a tabe caed 1nemy.

    SQL Server Integration Services (SSIS)

    SQL Server Integration Services (SSIS) aows you to integrate smoothy with other appications and

    data sources.

    ou can use Integration Services to copy or downoad fies! send e0mai messages in response to events!

    update data warehouses! cean and mine data! and manage SQL Server ob,ects and data.

  • 7/26/2019 SQL Server 2008 Tutorial

    37/38

    In SQL Server $%%7 and higher!Data "ransformation Services(D"S) is no onger instaed with SQL

    Server. / D"S reated tass are now performed with SSIS.

    @here as D"S Aone

    If you have been woring with earier versions of SQL Server (SQL Server $%%% and earier)! you areprobaby famiiar with D"S. D"S aowed you to transfer data between disparate sources into one or

    more destinations.

    @e! starting from SQL Server $%%7! D"S has been deprecated. D"S is no onger incuded with your SQL

    Server instaation.

    If you need D"S0type functionaity in SQL Server $%%-! you wi need to use SQL Server Integration

    Services.

    Bacwards 6ompatibiity

    ?or bacwards compatibiity! Microsoft has provided instaation fies that provide run0time support for

    D"S pacages. "his wi be usefu if you have aready created D"S pacages in an earier version of SQL

    Server. ?or more information seeSupport for Data "ransformation Services (D"S) in SQL Server $%%-on

    the MSDE website.

    SQL Server 1#press J SSIS

    SQL Server Integration Services is not avaiabe in the 1#press or @orgroup editions of SQL Server. If

    you need to use Integration Services! you need at east SQL Server Standard edition. /nd! if you need to

    use advanced features (such as data mining! te#t mining and ceansing or fuCCy transforms)! you wi

    need SQL Server 1nterprise edition.

    ?or more information on SQL Server Integration Services! chec out SQL Server Integration Serviceson

    the MSDE website.

    SQL Server Suar*

    6ongratuations for reaching the end of this SQL Server tutoria>

    SQL Server is a powerfu appication! and this tutoria has provided an overview of the main concepts

    invoved in administering SQL Server $%%- 1#press.

    "o recap briefy! we*ve4

    6reated databases

    6reated database tabes

    Inserted data into those tabes

  • 7/26/2019 SQL Server 2008 Tutorial

    38/38

    Looed at server roes

    Learned about database schemas

    Looed at ined servers

    and more

    $"at +e't6

    If you haven*t aready! chec out the SQL Server $%&' tutoria.

    /so! there were a coupe of areas we didn*t touch on during this tutoria. "his is mainy due to the fact

    that it is aimed at the free SQL Server 1#press version! which has its imitations.

    / is not ost though. My SQL Server $%%% tutoria covers some of the areas that weren*t incuded here.

    ?or e#ampe! you can earn about the SQL Server /gentforscheduing ,obsto run automaticay. ou canaso read about the SQL ;rofier! which aows you to monitor events within your SQL Server.

    "he most ogica ne#t step from earning SQL Server is toearn SQLitsef (if you haven*t aready done

    this that is). SQL stands for Structured Query Language and enabes you to perform database reated

    tass programaticay. Most of the tass in this tutoria can be done programaticay using SQL.

    ;robaby the most common use for SQL is to wor with the data in the database. ?or e#ampe! to insert

    data! seect data! update data! or to deete data. /ny database driven website wi have many SQL

    statements doing this stuff.

    "o earn more about SQL! chec out the SQL tutoria.

    http://www.quackit.com/sql_server/sql_server_2014/tutorial/http://www.quackit.com/sql_server/tutorial/sql_server_agent.cfmhttp://www.quackit.com/sql_server/tutorial/sql_server_agent_jobs.cfmhttp://www.quackit.com/sql_server/tutorial/sql_server_agent_jobs.cfmhttp://www.quackit.com/sql_server/tutorial/sql_profiler.cfmhttp://www.quackit.com/sql/tutorial/http://www.quackit.com/sql/tutorial/http://www.quackit.com/sql/tutorial/http://www.quackit.com/sql_server/sql_server_2014/tutorial/http://www.quackit.com/sql_server/tutorial/sql_server_agent.cfmhttp://www.quackit.com/sql_server/tutorial/sql_server_agent_jobs.cfmhttp://www.quackit.com/sql_server/tutorial/sql_profiler.cfmhttp://www.quackit.com/sql/tutorial/http://www.quackit.com/sql/tutorial/