SQL Fundamentals
SQL Fundamentals
SQL Fundamentals
Results:
Certified Student Course Curriculum - Version 2.0 Page 169
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals SQL Server Reports
SQL Server Reports
2
Another powerful feature in SQL Server is SQL Server Reports. There is a set of
canned reports in SQL Server Management Studio that can help gather information in
common areas. There are reports for CPU, memory, disk, sessions, queries,
transactions, and more.
Steps for Viewing SQL Server Reports
1. In SQL Server Management Studio, connect to the server.
2. Expand the Databases node, and then select your database.
3. Right-click the database name and select Reports > Standard Reports. As you can
see, there are many reports available.
SQL Server Fundamentals SQL Server Reports
Page 170 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Reports (continued)
2
4. Select a report and view it in the SQL Server Management Studio interface.
Activity
1. If you are not in SQL Server Management Studio, access it now from the Start
menu > All Programs > Microsoft SQL Server 2008 R2.
2. On the Object Explorer pane, expand the Databases node.
3. Right-click the mas500_app database.
4. Select Reports > Standard Reports > Disk Usage by Table.
5. Take a few minutes to explore the information on the report.
Certified Student Course Curriculum - Version 2.0 Page 171
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Other Performance Management Tools
Other Performance Management Tools
2
In addition to the Microsoft SQL Server Profiler tool available with Microsoft SQL
Server, there are other tools worth mentioning. One such tool, Performance Analysis
for SQL Server developed by Quest Software, can also assist in monitoring and
troubleshooting performance issues. The tool uses a graphical interface to
continuously provide performance status of the SQL Server.
Important: It is recommended that you use Performance Analysis in a test
environment before placing it on a production server.
SQL Server Fundamentals Challenge Questions - Part VI
Page 172 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Challenge Questions - Part VI
2
1. Name a feature in SQL Server that can be used to determine resource bottlenecks
regarding CPU, memory, and disk input/output.
_____________________________________________________________
2. List at least three standard reports that come with SQL Server that show
information for troubleshooting problems.
_____________________________________________________________
_____________________________________________________________
_____________________________________________________________
Certified Student Course Curriculum - Version 2.0 Page 173
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Lab Exercise - Monitoring Performance and Activity
Lab Exercise - Monitoring Performance and Activity
2
1. Access the SQL Server Profiler and create a counter to monitor the Physical and
%Idle Time counters. (page 159).
2. Access the Activity Monitor and determine the following: (page 164)
How many processes are currently running? __________________________
Are there any waits taking place on the server? ________________________
Page 174 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Lesson 10
SQL Server Fundamentals
Backing Up and Restoring Databases
10 2
Most system administrators agree that a clearly defined and consistently executed
backup plan is crucial to the safety of data in the case of application or hardware
failure, physical or electrical disaster, or human error or malicious behavior. In this
lesson, you will learn how to back up, restore, and detach and attach databases in your
system. You will also learn about transferring and copying databases as well as setting
important database options.
The topics in this lesson include:
Backing Up a Database
Restoring a Database
Detaching and Attaching a Database
Transferring and Copying Databases
Setting Database Options and Filegrowth Settings
Certified Student Course Curriculum - Version 2.0 Page 175
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Backing Up a Database
Backing Up a Database
2
You should determine when and how often you back up your systems data. You
should also consider implementing a set schedule where you back up your databases
at regular intervals. This section outlines how to manually back up your data;
however, a backup can be scheduled on a regular basis using maintenance plans. For
more information, see Creating Maintenance Plans on page 195.
Backup and recovery plans should meet the following needs of an organization:
Minimize loss of data
Minimize downtime
Minimize disruptions
Backup Considerations
Unique situations may indicate that its time for a backup. Typically, you should back
up your data any time your system experiences a change in environment. You should
consider both the hardware and software when determining if a backup is needed.
Common milestones include:
Immediately after an installation
Before making any hardware changes
Before importing large amounts of data
Before upgrading any software on your system to new versions or installing new
components or modules
If you expect power failure, such as during bad weather
Before customizing any part of the software
Before closing a period, fiscal year, or Payroll year in Sage ERP MAS 200 SQL
Note: In addition to backing up the databases on the Database Server (SQL Server),
you should copy the entire Sage ERP data folders on the Application Server and store
them in a secure location. Backups on the Database Server and Application Server
should be performed at the same time.
It is also important to note that how and where you handle your backups depends on
the various conditions of each company and situation. How you implement your
backups takes careful consideration and should be addressed with your company and
I.S. group.
SQL Server Fundamentals Backing Up a Database
Page 176 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Backing Up a Database (continued)
2
Types of Backups
There are three main types of backups available in SQL Server:
Full backups: Consists of a complete copy of a database. This type of backup
captures all pages in the database that contain data.
Differential backups: This type of backup captures data that has changed since
the last full backup. The differential backup cannot exist until a full backup is
performed.
Transaction Log backups: Copies all the log records that have been written to
the transaction log since the last full backup or transaction log backup. A Full
backup is required in order to create a Transaction Log backup.
The needs of your client will help determine which backup method to use.
If backups are needed once a day, a full backup in the evening will solve this
issue.
If multiple backups during the day are needed, you could do one full backup in the
middle of the night and differential backups or transaction log backups throughout
the day.
It is also important to know when the tape backup will occur.
A preferred backup method is to back up your Sage ERP MAS 200 SQL
databases to a local drive and then back up the files created by SQL Server. You
would then have two backup copies of the data.
Scheduling Database Backups
You can also schedule a backup using the Maintenance Plans option in SQL Server
Management Studio Options. Consider implementing a set schedule to back up your
databases at regular intervals. If your hardware fails, you can recover with a minimum
of data loss. For more information, see Creating Maintenance Plans on page 195.
The backup strategy for different each company is unique. You should consider
beginning with daily backups, then adjust as needed based on your particular
companys needs.
Certified Student Course Curriculum - Version 2.0 Page 177
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Backing Up a Database
Backing Up a Database (continued)
2
Steps for Performing a Database Backup
1. In SQL Server Management Studio, locate and right-click the database you want
to back up.
SQL Server Fundamentals Backing Up a Database
Page 178 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Backing Up a Database (continued)
2
2. From the Tasks menu, select Backup.
Use the General page to select the type of backup and destination.
It is recommended that you perform a Full backup initially.
- Every company must carefully weigh the factors unique to their environment
when creating backups.
Be sure to use the database name in the file name entered for the backup.
If you are changing the recovery model, perform a Full backup, restart your SQL
Server, and then rebuild the indexes.
The Transaction Log is available only if the recovery model is set to Bulk-logged
or Full.
Click this button to
specify the backup
location and file
name.
Choose the type of
backup you want to
perform: Full or
Differential.
Select this check box
if you are creating a
copy of a database.
For example, you
could create a copy of
the production
database for testing
purposes.
Certified Student Course Curriculum - Version 2.0 Page 179
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Backing Up a Database
Backing Up a Database (continued)
2
3. After defining the information on the General page, select Options under the
Select a page section.
4. Ensure the Back up to the existing media set check box is selected.
5. Select the Overwrite all existing backup sets check box.
6. In the Reliability section, select the Verify backup when finished check box. This
ensures you will be notified when the backup is complete.
7. In the Compression section, select Compress backup from the Set backup
compression drop-down.
Note: Creating compressed backups is supported only in SQL Server 2008
Enterprise and later; however, beginning in SQL Server 2008, every edition can
restore a compressed backup.
A compressed backup is smaller than an uncompressed backup of the same data,
compressing a backup typically requires less device I/O and usually increases
backup speed significantly.
SQL Server Fundamentals Backing Up a Database
Page 180 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Backing Up a Database (continued)
2
8. Click OK to start the backup process. A progress bar displays as the system backs
up the database with the file name entered. It will then verify the integrity of the
backup and display a message that the backup was completed successfully.
9. Click OK when prompted that the database was backed up successfully.
Activity
Use the following steps to back up a database.
1. If you are not in SQL Server Management Studio, access it now from the Start
menu > All Programs > Microsoft SQL Server 2008 R2.
2. In the Object Explorer (View menu > Object Explorer), expand the Sage_SQL
node and then expand the Databases node.
3. Right-click the mas500_app database and then select Tasks > Backup.
4. At the Backup type field, select Full.
5. Select the following as the destination for the backup:
C:\Program Files\Microsoft SQL Server\MSSQLSERVER\MSSQL\Backup
6. Select Options under the Select a page section.
7. Select the Verify backup when finished check box.
8. Click OK to start the backup.
9. Click OK when the "completed successfully" message displays.
10. In Windows Explorer, verify that the backup file was saved to the destination
location indicated. The backup file will have a .bak file extension.
Certified Student Course Curriculum - Version 2.0 Page 181
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Restoring a Database
Restoring a Database
2
After creating a backup, you can restore it. The Restore Database window allows you
to define information about the destination and source databases for the restore
process.
Steps for Restoring a Database
1. From the Microsoft SQL Server 2008 program group, select SQL Server
Management Studio.
2. In the Object Explorer pane, expand the node for your server and then expand the
Databases node.
3. Locate and right-click the database you want to restore.
You can choose Database if the backup occurred on the same server. You are
then provided with a list of backups that have been performed on this server.
SQL Server Fundamentals Restoring a Database
Page 182 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Restoring a Database (continued)
2
4. From the right-click menu, select Tasks > Restore > Database.
If restoring a database over an existing one, select the database you want to
restore over from the To database drop-down.
If you are bringing in a database from an outside source, select From Device.
5. The name of the database you are restoring displays in the To database drop-
down. To create a new database, you can enter its name.
Select this option and
then the ellipsis
button to specify the
backup media and
location for your
restoration process.
Certified Student Course Curriculum - Version 2.0 Page 183
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Restoring a Database
Restoring a Database (continued)
2
6. In the Source for restore section, select the From Device option and click the
ellipsis button to specify a backup that was saved previously.
7. Click Add.
8. Select the backup file and click OK.
9. On the General page, select the Restore check box for the backup set being
restored.
10. Scroll to the right to review the database file components.
Click Add to locate
the file.
SQL Server Fundamentals Restoring a Database
Page 184 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Restoring a Database (continued)
2
11. Under the Select a page pane, select Options.
12. In the Recovery state section, select the Leave the database ready to use... option
selected.
Note: This is the default option and is equivalent to specifying WITH
RECOVERY in a RESTORE statement (T-SQL). Under the Full recovery model,
or Bulk-Logged recovery model, select this option only if you are restoring all the
log files now.
Activity
Use the following activity to restore the database you backed up in the previous
activity.
1. If you are not in SQL Server Management Studio, access it now from the Start
menu > All Programs > Microsoft SQL Server 2008 R2.
2. In the Object Explorer (View menu > Object Explorer), expand the Sage_SQL
node and then expand the Databases node.
3. Right-click the mas500_app database and then select Tasks > Restore >
Database.
4. At the To Database field, select the mas500_app database.
5. Select the From device option and click the ellipsis button.
6. Click Add to locate the mas500_app.bak file and click OK.
7. In the Specify Backup window, click OK.
8. In the "Select the backup sets to restore" section, select the Restore check box.
9. In the Recovery state section, select the Leave the database ready to use... option.
10. Click OK.
11. When prompted with the "completed successfully" message, click OK.
Use the ellipsis button
to change the
database file (.mdf)
path.
Certified Student Course Curriculum - Version 2.0 Page 185
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Detaching and Attaching a Database
Detaching and Attaching a Database
2
As an alternative to backup and restore of databases onto another server or drive, you
can detach a database from one server and attach it to another. A detached database
cannot be used until it is attached re-attached.
When you detach a database, it leaves the .mdf and .ldf files intact in the SQL Data
directory, but removes it from the list of databases with SQL Server Management
Studio.
This process can be quicker than running a backup and restore process.
You can also have a copy of the original .mdf and .ldf files with demo data, which can
easily be re-attached for a quick refresh of the data.
Note: Before detaching a database, verify there are no Sage ERP MAS 500 users
connected to the databases.
Important: If using a recovery method of Full or Bulk Logged, be sure to create a
backup prior to detaching.
Steps for Detaching and Attaching Databases
1. In SQL Server Management Studio, right-click the database, and then select Tasks
> Detach.
Review the information in the window for any connections before detaching the
database.
SQL Server Fundamentals Detaching and Attaching a Database
Page 186 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Detaching and Attaching a Database (continued)
2
2. Click OK to detach the database, and then click OK again at the confirmation
message.
3. To attach the database, right-click the Databases node, and then select Tasks >
Attach.
All of the respective files should reside in the same directory location. If not,
select the .mdf file, and modify the paths accordingly for the .ldf and .ndf
files.
4. Click Add. The Locate Database Files window appears. Select the .mdf file from
the Program Files\Microsoft SQL Server\MSSQL\Data directory that relates to
your detached database.
5. Click OK to attach the database, and then click OK again at the confirmation
message.
Certified Student Course Curriculum - Version 2.0 Page 187
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Transferring and Copying Databases
Transferring and Copying Databases
2
At times, you may find it useful to copy an existing set of Sage ERP databases to
create a new set of databases on the same SQL Server or on a different SQL Server.
For example, you might decide to create a copy of your existing production
databases in order to create an environment in which you can safely test new
upgrades, perform customizations, use for training purposes etc.
Considerations When Creating a New Set of Databases on the Same
Server
Sage ERP users of the same name in both sets of databases share a logon.
If a copy of the databases is made on the same SQL Server, be aware that you will
be limited in your ability to change existing Sage
User information in either set of databases.
For existing users that are copied from one set of databases to the other, the
passwords cannot be changed and do not change the Application Role function in
Maintain Users.
New users created in one database set will not have access to any other database
set information.
For users to have access to data in the other databases, they must be created within
the appropriate database set.
No password should be defined for users that will have access to multiple
database sets.
It is recommended that you create unique logins for each set of databases on the
same server.
If you are using Windows NT authentication, changing user information does not
apply.
SQL Server Fundamentals Setting Database Options and Filegrowth Settings
Page 188 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Setting Database Options and Filegrowth Settings
2
Setting Database Options and Filegrowth Settings
One of the most important properties you can manage within your databases are size
and growth properties of files. As more data is stored in the database, you will need to
manage the size and growth of these files. One property that you can define is the
Autogrowth property of a file. Autogrowth allows you to control how the file will
expand after the maximum file limit is reached. In this section, you will learn how to
set this property along with other database options.
For the following example, a new database was created by a team that developed the
WeSeller application (an in-house application). A technical audit has highlighted that
inappropriate database options were specified. The following section will show you
how to set the correct database options to ensure the company meets its standards:
Full Recovery Model
Autoclose disabled
Autoshrink disabled
Database compatibility level is set to 100
File growth is set to 10 MB on both the data and log files.
Steps for Setting Database Options
1. In SQL Server Management Studio, right-click the database and then select
Properties.
Certified Student Course Curriculum - Version 2.0 Page 189
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Setting Database Options and Filegrowth Settings
Setting Database Options and Filegrowth Settings (continued)
2
2. Select Files under the Select a page section.
3. In the Database files section, select the Autogrowth field in a row and click the
ellipsis button to change the autogrowth setting.
4. In the Change Autogrowth window that displays, select whether to define the file
growth by percent or megabytes.
5. You can also select for restricted or unrestricted file growth.
6. Click OK.
7. In the Database files pane, you can also change the value at the Initial Size field
for a row.
8. Select Options under the Select a page section.
SQL Server Fundamentals Setting Database Options and Filegrowth Settings
Page 190 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Setting Database Options and Filegrowth Settings (continued)
2
Several database-level options that determine the characteristics of the database
can be set for each database.
- These options are unique to each database and do not affect other databases.
When the Auto Close option is enabled, the database is shut down cleanly and its
resources are freed after the last user exits. The database automatically reopens
when a user tries to use the database again. When set to disabled, the database
remains open after the last user exits
When the Auto Shrink option is enabled, the database files are candidates for
periodic shrinking. Both data file and log files can be shrunk automatically by
SQL Server. AUTO_SHRINK reduces the size of the transaction log only if the
database is set to SIMPLE recovery model or if the log is backed up. When
disabled, database files are not automatically shrunk during periodic checks for
unused space.
9. On the Options page, make sure SQL Server 2008 (100) is selected.
10. At the Recovery model field determine which recovery model to use.
Note: Under the Full recovery model, if transactions have been marked in each of
the related databases, you can recover the database to a consistent point. This
requires restoring each of the databases with the same transaction mark as the
recovery point for each. However, using a mark for a recovery point loses any
transactions committed after that point.
Certified Student Course Curriculum - Version 2.0 Page 191
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Setting Database Options and Filegrowth Settings
Setting Database Options and Filegrowth Settings (continued)
2
Activity
In this activity, you will
1. If you are not in SQL Server Management Studio, access it now from the Start
menu > All Programs > Microsoft SQL Server 2008 R2.
2. In the Object Explorer (View menu > Object Explorer), expand the Sage_SQL
node and then expand the Databases node.
3. Right-click the mas500_app database and then select Properties.
4. Select Files under the Select a page section.
5. In the Database files section, in the first row, click the ellipses button at the
Autogrowth field.
6. In the Change Autogrowth for mas500_app window that displays, make sure the
In Megabytes option is selected and type .
7. Click OK.
8. Repeat these same autogrowth steps for the second row.
9. Change the value at the Initial Size field for the first row to and for the
second row.
10. Select Options under the Select a page section.
11. At the Recovery model field, select Full.
12. Make sure the value at the Compatibility level field is set to SQL Server 2008
(100).
13. At the Auto Close and Auto Shrink fields, make sure False is selected.
SQL Server Fundamentals Challenge Questions - Part VII
Page 192 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Challenge Questions - Part VII
2
1. What are the three types of backups you can perform in SQL Server?
_____________________________________________________
_____________________________________________________
_____________________________________________________
2. What is an alternative to backing up and restoring a database?
_____________________________________________________
Certified Student Course Curriculum - Version 2.0 Page 193
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Lab Exercise - Creating a Backup and Restore
Lab Exercise - Creating a Backup and Restore
2
1. Create a backup of the mas500_app database using the Full backup type.
(page 175)
2. Make to verify when the backup is finished.
3. Restore the backup you created using the "Leave the database ready to use..."
option. (page 181)
Page 194 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Lesson 11
SQL Server Fundamentals
Working with Maintenance Plans
11 2
Maintenance plans allow you to automate tasks for maintaining your database.
The topics in this lesson include:
Creating Maintenance Plans
Certified Student Course Curriculum - Version 2.0 Page 195
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Creating Maintenance Plans
Creating Maintenance Plans
2
Maintenance plans create a workflow of the tasks required to make sure that your
database is optimized, is regularly backed up, and is free of inconsistencies. The
Maintenance Plan wizard creates core maintenance plans; however, you can also
manually create plans.
Note: Maintenance plans only run against databases set to compatibility level 80 or
higher.
Note: The user login account must be a member of the sysadmin role to create and
manage maintenance plans, and to view them in Object Explorer.
Some of the tasks that can be performed in Maintenance Plans include:
Checking for data consistency: This task performs an internal consistency check
of the data and index pages within the database.
Shrinking a database: This task allows you to remove unused pages in the
database. This reduces disk space that can be returned to the operating system or
used for future growth.
Updating statistics: This task provides a way to update the statistics generated in
the database engine. Having up-to-date statistics means the SQL Server will take
the correct path to the data, which means index scans and table scans will be more
accurate.
Cleaning up history: This task deletes the historical data related to database
backups and restorations as well as Maintenance Plan activity.
Executing SQL Server Agent jobs: Allows you to select SQL Server Agent jobs
to run as part of the maintenance plan.
Backing up databases (Full, Differential, or Transaction Log): Allows you to
specify source databases, destination files or tapes, and overwrite options for the
backup type.
Re-building and reorganizing indexes: This task reorganizes data on the data
and index pages and also optimizes the distribution of data and free space on the
index pages. This allows for future faster growth.
Steps for Creating a Maintenance Plan
In the following steps, you will learn how to create a maintenance plan that backs up
the database, performs a consistency check, and rebuilds the indexes.
1. From the Microsoft SQL Server 2008 program group, select SQL Server
Management Options.
SQL Server Fundamentals Creating Maintenance Plans
Page 196 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Creating Maintenance Plans (continued)
2
2. Access the SQL Server Maintenance Plan Wizard by expanding the Management
node in SQL Server Management Options > right-clicking Maintenance Plans >
selecting Maintenance Plan Wizard.
3. In the SQL Server Maintenance Plan Wizard page that displays, click Next.
You can choose to
create a schedule for
all tasks or separate
schedules for each
task.
Certified Student Course Curriculum - Version 2.0 Page 197
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Creating Maintenance Plans
Creating Maintenance Plans (continued)
2
4. In the Select Plan Properties wizard page, enter a name for your plan and a
description.
5. You can choose to select whether to schedule each task individually or together.
In our example, we will select the "Single schedule for the entire plan or no
schedule" option to schedule all the tasks together.
6. Click Change. In the Job Schedule Properties window that displays, set the time,
frequency, and duration for performing the consistency checks on the databases.
In our example, we will enter Daily at the Occurs drop-down, and type 10:00 pm
for the time.
Use the Change button to set the time, frequency, and duration for performing the
consistency checks on the databases.
SQL Server Fundamentals Creating Maintenance Plans
Page 198 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Creating Maintenance Plans (continued)
2
7. Click Next.
8. Select the tasks you want to perform and click Next.
The Select Maintenance Task Order window allows you to determine the order in
which to perform the tasks.
Certified Student Course Curriculum - Version 2.0 Page 199
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Creating Maintenance Plans
Creating Maintenance Plans (continued)
2
9. Click Next.
10. For each task, select whether to include all databases or one or more databases at
the Databases drop-down and define any other options for the task as needed.
You can change the
folder location by
clicking the ellipsis
button.
SQL Server Fundamentals Creating Maintenance Plans
Page 200 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Creating Maintenance Plans (continued)
2
11. Click Next in each task window.
12. Click Next.
13. In the Complete the Wizard window, verify your choices and click Finish.
You can change the
folder location by
clicking the ellipsis
button.
Certified Student Course Curriculum - Version 2.0 Page 201
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Creating Maintenance Plans
Creating Maintenance Plans (continued)
2
14. In the Maintenance Plan Wizard page, after processing is complete, click Close.
15. In SQL Server Management Studio, on the Object Explorer pane, expand the
Management node and then the Maintenance Plans node. Notice the new
maintenance plan.
16. You can also view the plan under the SQL Server Agent node. Expand the SQL
Server Agent node and then expand the Jobs node.
SQL Server Fundamentals Creating Maintenance Plans
Page 202 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Creating Maintenance Plans (continued)
2
Activity
In the following activity, you will create a maintenance plan that checks for database
integrity, rebuild indexes, and create a full backup on a daily basis.
1. If you are not in SQL Server Management Options, access it now from the
Microsoft SQL Server 2008 program group.
2. Access the SQL Server Maintenance Plan Wizard by expanding the Management
node in SQL Server Management Options > right-clicking Maintenance Plans >
selecting Maintenance Plan Wizard.
3. On the Welcome page, click Next.
4. On the Select Plan Properties page, type at the
Name field.
5. Type the following description:
6. Make sure the Single schedule for the entire plan or no schedule option is selected
and click Change.
7. At the Occurs field, select Daily.
8. At the Occurs once at field, enter .
9. Click Next.
10. On the Select Maintenance Tasks page, select the Check Database Integrity,
Rebuild Index, and Back Up Database (Full) check boxes are selected and click
Next.
11. On the Select Maintenance Task Order page, keep the order of the tasks as is and
click Next.
12. On the Define Database Check Integrity Task page, at the Databases drop-down,
select All databases, and click OK. Click Next.
13. On the Define Rebuild Index Task page, at the Database drop-down, select All
databases, and click OK.
14. On the Define Back Up Database (Full) Task page, at the Databases drop-down,
select All databases, and click OK.
15. Make sure the Create a backup file for every database option is selected, and click
Next.
Certified Student Course Curriculum - Version 2.0 Page 203
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Creating Maintenance Plans
Creating Maintenance Plans (continued)
2
2
16. On the Select Reports Options page, click Next.
17. On the Complete the Wizard page, click Finish.
18. On the Maintenance Plan Wizard Progress page, click Close.
19. In SQL Server Management Studio, on the Object Explorer pane, expand the
Management node and then expand the Maintenance Plans node to view your new
maintenance plan.
Certified Student Course Curriculum - Version 2.0 Page 204
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Challenge Questions - Part VIII
Challenge Questions - Part VIII
2
1. List at least three tasks that you can include in a maintenance plan.
_________________________________________________________
_________________________________________________________
_________________________________________________________
2. After creating your maintenance plan, which two places can you view it from in
SQL Server Management Studio?
_________________________________________________________
_________________________________________________________
Certified Student Course Curriculum - Version 2.0 Page 205
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Lab Exercise - Creating a Maintenance Plan
Lab Exercise - Creating a Maintenance Plan
2
1. In SQL Server Management Options, create a plan to reorganize and rebuild the
indexes and backup all the databases using the Full method. (page 195)
2. Perform the tasks on all databases.
3. Schedule all the tasks to occur daily at 4:00 am. (page 199)
4. After creating the plan, view it under the Maintenance Plan node in SQL Server
Management Studio. (page 201)
Page 206 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Lesson 12
SQL Server Fundamentals
Understanding SQL Server Integration Services
12 2
SQL Server Integration Services integrates information from various data sources. It
allows you to go beyond just moving data around by using Extract, Transform, and
Load (ETL) to create applications that manage databases and system resources, for
example.
The topics in this lesson include:
Overview of SQL Server Integration Services
Developing Packages Using SSIS
Certified Student Course Curriculum - Version 2.0 Page 207
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Overview of SQL Server Integration Services
Overview of SQL Server Integration Services
2
SQL Server Integration Services, also known as SSIS, provides the ability to
transform data into meaningful and actionable information. SQL Server Integration
Services satisfies the traditional demands of Extract, Transform, and Load (ETL)
operations and general-purpose data integration. It also provides a robust, flexible,
scalable, and extensible architecture.
Challenges
Some challenges include:
Retrieve and merge data from multiple sources.
Cleanse and transform the data.
Load the data into appropriate data stores for analysis and reporting.
Enterprises spend 60 to 80% of their resources in the data-integration stage. With
SSIS, you can import and export data from relational databases.
Business Scenarios
The different business scenarios for using SSIS are:
Importing and exporting data from relational databases.
Populating data warehouses (ETL).
Cleaning and standardizing data.
Merging data from heterogeneous data stores.
Automating administrative tasks.
About SSIS Packages
A package in SSIS is the basic unit of work, deployment, and execution. It can be
designed graphically or built programmatically and is saved in XML format to the file
system or SQL Server. An SSIS package is an organized collection consisting of:
Connection managers: Logical representation that is stored in the package and
cannot be shared between packages.
Control flow components: Is a process-oriented workflow engine. A package
consists of a single control flow. Control flow elements are: containers, tasks,
precedence constraints, and variables. Control flow allows you to execute and
build packages and data flows programmatically. You can also develop custom
tasks and extend process functionality with a Script Task. Custom tasks and
transformations can be packaged and can include a user interface.
Data flow components: Encapsulates the data flow engine.
SQL Server Fundamentals Overview of SQL Server Integration Services
Page 208 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Overview of SQL Server Integration Services (continued)
2
Event handlers: Event handlers respond to events raised during package
execution and have the same structure as a package, including control flow and
data flow. Examples include:
- Send an email when a warning or error occurs.
- Retrieve system information when a package runs.
- Clean up temporary data storage when a package completes.
Log Providers
You can implement logging in packages, containers, and tasks. You can also capture
runtime information about a package for auditing and troubleshooting after each
execution. Examples include:
Log warning or error events.
Log operator name and package execution time.
Configurations
Multiple configurations are possible per package. You can also have shared
configurations across packages. Configurations of SSIS packages include:
Dynamic initialization of a package
Variety of configuration sources, such as:
- SQL
- XML
- Registry
- Environment variable
- Parent package
Deployment Tools
The following are deployment tools that can be used with SSIS packages:
Deployment Utility: This utility assembles all packages in a project for
installation on a different server. This includes all related files in the project, such
as configuration files or documentation.
Package Installation Wizard: This wizard guides you through the steps to install
packages. This allows you to make configuration changes during the installation
and deploy packages to the server file system or SQL Servers msdb database.
Certified Student Course Curriculum - Version 2.0 Page 209
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS
2
The first step when developing packages is to create the Integration Services project.
In set of steps below, you will learn how to develop a package that exports data ready
for import into an external system. In the second set of steps, you will automate the
execution of this package on a schedule.
Steps for Creating an Integration Services Project
1. From the Start menu, select All Programs > Microsoft SQL Server 2008 > SQL
Server Business Intelligence Development Studio.
SQL Server Fundamentals Developing Packages Using SSIS
Page 210 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
2. From the File menu, select New > Project.
3. In the Projects types pane, ensure Business Intelligence Projects is selected.
4. In the Templates pane, select Integration Services Project.
5. Type a name for the project, such as CustomerCreditExtract.
6. In the Location field, enter C:\Applications and click OK.
Certified Student Course Curriculum - Version 2.0 Page 211
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
Steps for Developing the Package
The following steps will show you how to develop a package that exports data into an
external system.
1. From the File menu, select Save Package.dtsx As and rename the file to
something meaningful.
2. When prompted to rename the package object, click Yes.
3. From the View menu, select Toolbox.
SQL Server Fundamentals Developing Packages Using SSIS
Page 212 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
4. When the Toolbox appears, click the pin icon to make it stay visible as shown
below:
5. To provide more screen real-estate, unpin both the Solution Explorer and
Properties windows if they are visible.
To archive any existing export files before creating a new export file
In our example, there is a folder called C:\Applications\CreditManagement\Import
associated with the CreditManagement application. Each day at 4:00 am, details of
Customers' credit limits need to be exported from the mas500_app database into a file
in that folder. Before exporting the data, we need to move any existing files in the
folder to the C:\Applications\CreditManagement\Archive folder to avoid overwriting
them.
6. Right-click in the center of the control flow design surface and click Variables
7. In the Variables window, click the Add Variable icon:
8. For the Name of the variable, enter FileName. Scroll to the right of the window
and in the Data Type column, choose String.
9. Add another variable called NewFileName and also make it a String.
Note: Variable and object names in SSIS are case-sensitive.
Certified Student Course Curriculum - Version 2.0 Page 213
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
10. Click the Toolbox tab, under the heading Control Flow Items, click the Foreach
Loop Container and drag it to the Control Flow area of the package.
11. Right-click the Foreach Loop Container and click Edit.
12. In the Foreach Loop Editor dialog window, click Collection property page.
13. In the Foreach Loop Editor window, enter the properties as shown in the
following table:
Property Value
Enumerator Foreach File Enumerator (even though this may already
be shown, re-select it to bring up the enumerator
configuration)
SQL Server Fundamentals Developing Packages Using SSIS
Page 214 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
14. In the Enumerator configuration section, enter the properties as shown in the
following table:
15. In the Foreach Loop Editor dialog window, click Variable Mappings property
page and enter the properties as shown in the following table:
Note: The variable mapping will take the fully qualified name of the file (which
includes the path, name, and extension of the file) and update the value of the variable
for every loop of the package.
16. Right-click the Foreach Loop Container and click Rename. Make the new name
of the container For Each Existing File.
17. Click OK to Save the changes.
18. From the Toolbox, drag a Script Task inside the For Each Existing File container.
Property Value
Folder \\SQLTRAIN\Applications\CreditManagement\Import
Property Value
Variable User:: FileName
Index 0
Certified Student Course Curriculum - Version 2.0 Page 215
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
19. Right-click the Script Task and select Rename. Make the new name Calculate
Output Filename
20. Right-click the Calculate Output Filename task and click Edit.
21. In the ScriptLanguage drop-down, select Microsoft Visual Basic 2008.
22. Click in the value area for the ReadOnlyVariables and click the Ellipsis that
appears.
23. In the Select Variables dialog, tick the box beside User::FileName and click OK.
24. Click in the value area for the ReadWriteVariables and click the Ellipsis that
appears.
25. In the Select Variables window, select the check box beside User::NewFileName
and click OK.
26. Click the Edit Script button.
27. Scroll to the bottom of the code and add the following code (in one line) in the
location shown:
Note: this expression can be copied and pasted from the file
C:\Temp\Lab7Snippets.txt
SQL Server Fundamentals Developing Packages Using SSIS
Page 216 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
28. From the ssisscript - Integration Services Script Task dialog, choose Exit from the
File menu.
29. In the Script Task Editor, click OK.
30. From the Toolbox, drag a File System Task inside the For Each Existing File
container under the Calculate Output Filename task.
31. Click on the Calculate Output Filename task and drag the green precedence
constraint arrow down onto the new File System Task.
32. Right-click the File System Task and select Rename. Make the new name Rename
Existing File.
33. Right-click the Rename Existing File task and select Edit.
34. Choose the following options and then click OK.
35. Right-click the Rename Existing File task, then choose Properties.
36. From the Properties toolbox, set DelayValidation to True.
37. From the File menu, click Save All.
Note: We have created a task to rename any existing file to the same name with the
date appended to the end of it. The file being renamed is coming from the variable
FileName and the destination name is in the NewFileName variable.
Certified Student Course Curriculum - Version 2.0 Page 217
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
Test initial functionality to make sure it works
38. Open Windows Explorer and navigate to the folder
C:\Applications\CreditManagement\Import.
39. In the right-hand pane, right-click the empty space and choose New then Text
Document.
40. Rename the document to TestDocument_1.txt.
41. In the right-hand pane, right-click the empty space and choose New then Text
Document.
42. Rename the document to TestDocument_2.txt.
43. Return to the Visual Studio window. From the Debug menu, choose Start
Debugging.
44. The package should execute and all tasks should be green when complete.
SQL Server Fundamentals Developing Packages Using SSIS
Page 218 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
45. In Windows Explorer, note that the filenames have now been changed by
appending today's date to them in the format YYYYMMDD.
46. From the Debug menu click Stop Debugging.
Add a task to move the renamed files to a new folder
47. From the Toolbox, drag another File System Task inside the For Each Existing
File container. Rename it to Move File.
48. Click on the Rename Existing File task and drag a green precedence constraint
down onto the new Move File task.
49. Right-click the Move File task and click Edit.
Certified Student Course Curriculum - Version 2.0 Page 219
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
50. Configure the settings as follows:
51. Click in the value area for the Destination Connection property and click the
down-arrow.
52. From the drop-down list, choose the option to create a New Connection.
53. Configure the File Connection Manager Editor as follows:
54. The folder name is:
\SQLTRAIN\Applications\CreditManagement\Archive
55. Click OK.
56. Click OK to close the File System Task Editor window.
57. Right-click the Move File task and choose Properties.
58. From the Properties toolbox, set DelayValidation to True.
59. From the File menu, click Save All.
60. Test the application.
61. From the Debug menu, click Start Debugging.
SQL Server Fundamentals Developing Packages Using SSIS
Page 220 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
62. The program should run to completion:
63. From the Debug menu, click Stop Debugging.
64. In Windows Explorer ensure that the files have been moved to the Archive folder:
65. In Visual Studio, drag a Data Flow task from the Toolbox onto the Control Flow
under (not in) the For Each Existing File container and rename it to Export Credit
Details.
66. Click the For Each Existing File container and drag a green precedence constraint
arrow down onto the new Export Credit Details task.
67. Right-click the Export Credit Details task and choose Edit.
68. In the Data Flow Editor, drag an ADO.NET Source onto the surface and rename it
to mas500_app Credit.
69. Right-click the mas500_app Credit data source and click Edit.
70. Click the New button to create a new connection manager.
71. In the Configure ADO.NET Connection Manager dialog, click New.
72. In the Connection Manager window, type the server name as SQLTRAIN.
73. From the Select or enter a database name drop-down, select mas500_app and
click OK.
Certified Student Course Curriculum - Version 2.0 Page 221
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
74. Click OK to close the Configure ADO.NET Connection Manager window.
75. In the ADO.NET Source Editor dialog, from the Data access mode drop down,
select SQL Command.
76. In the SQL Command Text section, type the following query:
77. Click the Preview button to preview the data then Close to close the preview
window. (Customer data should appear.)
78. Click OK to close the ADO.NET Source Editor.
79. From the toolbox, drag a Flat File Destination component onto the design surface
under the mas500_app Credit data source and rename it to Credit File.
80. Drag a green data connector from the data source (mas500_app Credit) to
destination (Credit File).
81. Right-click the Credit File destination and click Edit.
82. In the Flat File Destination Editor dialog, click New to create a new flat file
connection manager.
83. In the Flat File Format window, select Delimited and click OK.
SQL Server Fundamentals Developing Packages Using SSIS
Page 222 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
84. In the Flat File Connection Manager Editor, configure the screen as follows:
Note that the file name is:
\\SQLTRAIN\Applications\CreditManagement\Import\CreditDetails.txt
85. Click OK to close the window.
86. In the Flat File Destination Editor window, click on the Mappings pane then click
OK.
87. From the File menu, select Save All.
88. Test our package again.
89. From the Debug menu, click Start Debugging .
90. The program should run to completion and 69 rows should be transferred.
91. From the Debug menu, click Stop Debugging.
Certified Student Course Curriculum - Version 2.0 Page 223
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
92. In Windows Explorer note that a new CreditDetails.text file has been created in
the Import folder.
93. In Visual Studio, from the Debug menu, click Start Debugging.
94. Again the program should run to completion. Then form the Debug menu, select
Stop Debugging.
95. Now verify in Windows Explorer that the last file generated was in fact archived
to the Archive folder before another file was created.
Steps for Deploying and Scheduling Execution of the Package
1. First we will select an option to request a deployment utility that will let us easily
deploy the package. Then we will enable configurations for the package. This will
help greatly if we ever need to change the paths to files or use a different database
server.
2. From the Project menu, select CustomerCreditExtract Properties
3. In the CustomerCreditExtract Property Pages dialog, click on the Deployment
Utility pane.
SQL Server Fundamentals Developing Packages Using SSIS
Page 224 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
4. Configure the properties as shown:
5. Click OK to close the dialog.
6. Click the Control Flow tab, from the SSIS menu, click Package Configurations.
7. In the Package Configurations Organizer check the box to Enable package
configurations.
8. Click the Add button.
9. In the Package Configuration Wizard window, click Next.
10. In the Select Configuration Type window, enter the filename as
\\SQLTRAIN\Applications\CreditManagement\ExtractCustomerCredit.dtsconfig
and click Next.
11. In the Objects list, check the three Connection Managers:
12. Click Next.
13. In the Completing the Wizard window, enter the Configuration name as
ExtractCustomerCredit Configuration and click Finish.
14. In the Package Configurations Organizer window, click Close.
15. From the File menu, click Save All.
16. Build our package so it is ready for deployment.
17. From the Build menu, click Build CustomerCreditExtract.
Certified Student Course Curriculum - Version 2.0 Page 225
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Developing Packages Using SSIS
Developing Packages Using SSIS (continued)
2
Deploy the package
18. In Windows Explorer, navigate to C:\Temp.
19. Right-click the file CustomerCreditExtract.SSISDeploymentManifest and click
Deploy.
20. In the Welcome to the Package Installation Wizard window, click Next.
21. In the Deploy SSIS Packages window, choose SQL Server deployment and click
Next.
22. In the Server Name text box, type SQLTRAIN.
23. In the Package Path text box type a forward slash /.
24. Click Next.
25. In the Select Installation Folder window, click Next.
26. In the Confirm Installation window, click Next.
27. In the Configure Packages window, click Next.
28. When the package has deployed, click Finish.
Schedule the package for execution
29. If it is not already open, open SQL Server Management Studio and connect to the
SQLTRAIN database engine.
30. On the Object Explorer pane, expand the SQL Server Agent node.
31. Right-click Jobs and click New Job.
32. In the New Job window, set the Name textbox to Extract Customer Credit Details
then click on the Steps pane.
33. Click New to add a new job step.
34. In the New Job Step window, set the Step name to Extract and the Type to SQL
Server Integration Services Package.
35. In the Server dropdown on the General tab, type SQLTRAIN.
36. Click the Ellipsis to the right of the Package textbox and from the popup, select
the Extract package and click OK.
37. Click OK to close the New Job Step window.
38. In the New Job window, click the Schedules pane then the New button to create a
new job schedule.
SQL Server Fundamentals Developing Packages Using SSIS
Page 226 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Developing Packages Using SSIS (continued)
2
39. Configure the job as follows:
40. Click OK to save the schedule.
41. In the New Job window, click OK to save the job. We have now created and
scheduled our job. The final task is to test that it runs ok from within SQL Server.
42. In Object Explorer expand the Jobs node.
43. Right-click the Extract Customer Credit Details job and select Start Job At Step.
44. The job should now run successfully.
The package is now scheduled.
Certified Student Course Curriculum - Version 2.0 Page 227
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Challenge Questions - Part IX
Challenge Questions - Part IX
2
1. List at least one business case for using SQL Server Integration Services.
_______________________________________________________
2. Which two deployment tools can be used with SSIS packages?
_______________________________________________________
_______________________________________________________
Page 228 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Lesson 13
SQL Server Fundamentals
Disaster Recovery
13 2
A disaster recovery plan should define which databases and files should be backed up
on a regular basis. The plan should also determine where and how those files should
be protected.
The topics in this lesson include:
Planning for Disaster Recovery
High Availability Options
Certified Student Course Curriculum - Version 2.0 Page 229
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Planning for Disaster Recovery
Planning for Disaster Recovery
2
With disaster recovery, it is important to note that every company should adopt the
method that works best for their needs. For example, one company may save backups
on tape and ship them off-site to another location. Another company may use an
online backup service to store their backups. No two disaster recovery plans are alike
and many factors need to be considered when creating a plan.
Additionally, depending on which product you are using, you need to build around
that specific product. For example, Sage ERP MAS 200 SQL has a System database,
Company databases, and static files (flat files) on the Application Server. A disaster
recovery plan should define which databases and files would have to be backed up on
a regular basis. The process also needs to determine where and how these files should
be protected. The restore process would then determine the steps to restore the
required files in order to bring the application back on line in case of data loss.
Differences Between Disaster Recovery and High Availability
2
Disaster recovery entails restoring your system back to normal after a catastrophic
failure or extended outage. High availability typically involves local context, such as
keeping downtime to a minimum from day to day. Both involve people and processes
more than technology.
Creating a Plan
You should protect your system from user, database, and system errors, operating
system issues, hardware and application failures, security breaches, and external
issues, such as weather, power, etc.
Expect the Unexpected
You have to realize that outages will occur - the question is when; therefore, you must
be prepared to minimize or prevent common causes of downtime and outages. You
should also be proactive with people, processes, and technology.
Service Level Agreements
Service level agreements should be determined early in any project and should
include the following two objectives. The goal is to have no loss or downtime.
Recovery time objective (RTO)
Recovery point objective (RPO)
SQL Server Fundamentals Planning for Disaster Recovery
Page 230 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Planning for Disaster Recovery (continued)
2
What Defines Downtime?
First, you need to define what is considered downtime.
Planned vs unplanned
When systems are up but applications unusable
When systems are up but the network is down or too slow
Rebuilding After a Disaster
You should know ahead of time how to rebuild after a disaster. Considerations include
the following:
How to rebuild?
Where to rebuild?
Site access
Site restrictions
Security
Requirements
Requirements for a disaster recovery plan include the following:
Must meet Service Level agreements.
Must take into account the capabilities including technical and non-technical.
Must work within the budget.
Must be tested periodically.
Actions
Some things to consider when developing actions for the disaster recovery plan
includes:
Need clear steps, escalation points, and timelines.
The plan must be accessible.
Everything should be documented, including while being performed.
The call list should be up-to-date.
You should periodically revisit and revise the plan.
Certified Student Course Curriculum - Version 2.0 Page 231
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Planning for Disaster Recovery
Planning for Disaster Recovery (continued)
2
The Plan
The disaster recovery plan should include the following:
Must have a chain of command and someone must be in charge.
The correct people need to be in the correct role with no single points of failure.
People need to have the correct training and available, workable schedules
Support Contracts
Some things to think about regarding support contracts include:
Support contracts are often the deciding factor.
Must know who to contact, regarding hardware and software components.
Must understand and agree to the Service Level agreement.
Must know how to contact.
- Up-to-date call list
- Contract numbers and relevant information
Applications
Some things to think about regarding applications include:
Will the applications support a move to another server easily?
High availability and disaster recovery must be part of the initial plan.
SQL Server
Some things to think about regarding SQL Server include:
Backing up and restoring
Log shipping
Attaching/detaching databases
Database snapshots
Database mirroring
bcp utility (for bulk copy data between and instance of SQL Server and a data file
SQL Server Integration Services (SSIS)
Replication (more for data distribution than high availability or disaster recovery)
SQL Server Fundamentals High Availability Options
Page 232 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
High Availability Options
2
This section outlines some options you can use for high availability and also outlines
some barriers to availability.
Database Snapshots
Information about database snapshots includes the following:
Database snapshots are read only
Provides a static view of the database
Transaction consistent at point of time
Does not store all data pages
Reads only the original data pages
- Reads data from the snapshot if data has changed
- Reads data from the database if data has not changed
Increases I/0 of source database
The following illustration shows how database snapshots work:
Some database snapshot scenarios include:
Enabling mirroring database for reporting
Historical point-in-time reporting
Recovering from administrative error
Protecting against application or user error
Certified Student Course Curriculum - Version 2.0 Page 233
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals High Availability Options
High Availability Options (continued)
2
Barriers to Availability
Some barriers to availability include:
Business requirements, such as time and location, processes, and expectations.
Technology, such as hardware, DBMS software, and application software.
Primary server or DBMS barriers include:
- User or application error, such as accidental or malicious data modifications.
- Data access concurrency limitations, such as multiple transactions accessing
the same data and persistent data structure changes.
Failover Clustering
Some things to note about failover clustering include:
Failover clustering is aimed at server failure.
It is built on Microsoft Cluster Services (MSCS).
- Multiple nodes
- Automatic failover of instance
- Pass Cluster Validation for SQL Server 2008
There is zero-committed work loss.
Single copy of instance databases.
Supports a variety of SQL Server components.
SQL Server Fundamentals High Availability Options
Page 234 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
High Availability Options (continued)
2
The following illustration shows how failover clustering works.
Database Mirroring
Some things to note about database mirroring include:
Provides a hot standby (near instant)
Database failover
- Very fast automatic failover
- Can provide transparent client redirect
Zero committed work loss
There is some performance impact
Can have a maximum of one mirror for each database
Certified Student Course Curriculum - Version 2.0 Page 235
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals High Availability Options
High Availability Options (continued)
2
The following illustration shows how database mirroring with automatic failover
works.
SQL Server Fundamentals High Availability Options
Page 236 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
High Availability Options (continued)
2
Log Shipping
Some things to note about log shipping include:
It is a mature and reliable technology
There is no automated failover
It is essentially a process of:
- Back up transaction logs
- Copy logs to another server
- Restore the logs
Replication
Some things to note about replication include:
Mostly should be considered as a data distribution technology
Has many forms:
- Transactional
- Merge
- Snapshot
Not commonly used for High Availability
- Peer to peer transactional replication has a potential role
Certified Student Course Curriculum - Version 2.0 Page 237
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals High Availability Options
High Availability Options (continued)
2
Comparison of High Availability Options
The following charts compare the high availability features:
SQL Server Fundamentals Challenge Questions - Part X
Page 238 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Challenge Questions - Part X
2
1. Explain the difference between disaster recover and high availability.
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
_____________________________________________________
2. List at least three things a disaster recovery plan should include.
_____________________________________________________
_____________________________________________________
_____________________________________________________
SQL Server Fundamentals
Certified Student Course Curriculum - Version 2.0 Page 239
Copyright 2010 Sage Software, Inc. All rights reserved.
Appendix
3
The following topics are included in this Appendix:
Appendix A - Challenge Answers
Appendix B - Troubleshooting
Appendix C - Resources and References
SQL Server Fundamentals Challenge Answers
Page 240 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Appendix A Challenge Answers
4
page 29
1. List at least three things you should do before upgrading from SQL Server
2000/2005.
Document all existing systems.
Develop validation tests.
Develop performance benchmarks.
Capture baseline data for these.
Formulate and test a rollback plan.
Identify the upgrade stakeholders: application, database, hardware, infrastructure,
users, business sponsor.
page 65
1. Which utility should you run before installing SQL SErver 2008 if you are
upgrading from SQL Server 2000/2005?
Answer: The Install Upgrade Advisor available. which is available on the SQL
Server Installation Center window.
2. Explain briefly how to add a new server group in SQL Server Management
Studio.
Answer: In SQL Server Management Studio, select the View menu > Registered
Servers. Expand the Database Engine node and right-click a server or server
group. Select New Server Group. In the New Server Group Properties window,
enter a name and description for your new server group. You can then move
servers into your new server group folder.
Certified Student Course Curriculum - Version 2.0 Page 241
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Challenge Answers
Challenge Answers (continued)
5
page 79
1. Which tool in SQL Server provides management and security over the surface
area of local and remote instances on the SQL Server?
Answer: SQL Server Surface Area Configuration tool.
2. List at least three properties you can view and/or configure using the Server
Properties window.
Answer:
Determine where SQL Server is running.
Determine how much memory is being used by the server?
Determine how much memory is used for index and queries.
Determine how many processors are being used.
Determine the default fill factor.
Determine where the system default for new databases are to be stored.
View or set the network packet size.
View or set the authentication mode.
View or set permissions.
page 109
1. What is the quickest way to view the properties of a database in SQL Server?
Answer: Right-click the server name in SQL Server Management Studio.
2. Which page in the Database Properties window is used to set the options of the
database?
Answer: Options
3. What are the three recovery models?
Answer: FULL, BULK_LOGGED, SIMPLE
4. Explain how to quickly create a table in SQL Server?
Answer: In SQL Server Management Studio, expand the database you are adding
the table to. Next, right-click and select New Table. Create the columns fo the
table and define the data types. Make sure to create a primary key for one of the
columns. Save the table (File menu > Save Table_1).
SQL Server Fundamentals Challenge Answers
Page 242 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Challenge Answers (continued)
6
page 123
1. Which option under the Management node allows you to enforce policies for
configuring and managing SQL Server across an enterprise?
Answer: Policy Management
2. Which option under the Management node allows you to manage SQL Server
workload and system resource consumption?
Answer: Resource Governor
3. What does the SQL Server Logs option under the Management node allow you to
do?
Answer:
Record processes that have been completed successfully, such as backup and
restore operation, batch commands, and scripts.
Detect any problems with SQL Server, such as automatic recovery messages.
page 147
1. Which node in SQL Server Management Studio contains tools that allow you to
create alerts, jobs, and operators?
Answer: SQL Server Agent
2. Explain briefly how to create a job and a step within a job.
Answer: In SQL Server Management Studio, expand the SQL Server Agent node
and then right-click the Jobs node. After defining the job information on the
General page, select Steps and then click New. You can the enter the information
and parameters to use for the step in the New Job Step window. Click OK.
page 172
1. Name a feature in SQL Server that can be used to determine resource bottlenecks
regarding CPU, memory, and disk input/ouput.
Answer:
2. List at least three standard reports that come with SQL Server that show
information for troubleshooting problems.
Disk Usage
Disk Usage by Top Tables
Disk Usage by Partition
Certified Student Course Curriculum - Version 2.0 Page 243
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Challenge Answers
Challenge Answers (continued)
7
page 192
1. What are the three types of backups you can perform in SQL Server?
Answer:
Full
Differential
Transaction log
2. What is an alternative to backing up and restoring a database?
Answer: Detaching the database from one server and then attaching the database
to another server.
page 204
1. List at least three tasks that you can include in a maintenance plan.
Answer:
Check for data consistency
Shrink a database
Update statistics
Clean up history
Execute SQL Server Agent jobs
Back up databases
Rebuild and reorganize indexes
2. After creating your maintenance plan, which two places can you view it from
within SQL Server Management Studio?
Answer:
Under the Management > Maintenance Plans node
Under the SQL Server Agent > Jobs node
SQL Server Fundamentals Challenge Answers
Page 244 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Challenge Answers (continued)
8
page 227
1. List at least one business case for using SQL Server Integration Services.
Answer:
Importing and exporting data from relational databases
Populating data warehouses (ETL)
Cleaning and standardizing data
Merging data from heterogeneous data stores
Automating administrative tasks
2. Which two deployment tools can be used with SSIS packages?
Answer:
Development Utility
Package Installation Wizard
page 238
1. Explain the difference between disaster recover and high availability.
Answer: Disaster recovery involves restoring your system back to normal after a
catastrophic failure or extended outage. High availability typically involves local
context, such as keeping downtime to a minimum from day to day. Both involve
people and processes more than technology
2. List at least three things a disaster recovery plan should include.
Answer:
Must have a chain of command and someone must be in charge.
The correct people need to be in the correct role with no single points of
failure.
People need to have the correct training and available, workable schedules
9
Certified Student Course Curriculum - Version 2.0 Page 245
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Troubleshooting
Appendix B Troubleshooting
10
Detecting an Indexing Issue
In the following case, it is suspected that a particular query is consuming significant
resources on the server. The query is not overly complex but is executed frequently.
You need to investigate the query.
Steps for Viewing a Query In Action
1. If you are not in SQL Server Management Studio, access it now from the Start
menu > All Programs > Microsoft SQL Server 2008.
2. Make sure you have the Object Explorer pane open (View menu > Object
Explorer).
3. Expand the Database node.
4. Right-click the mas500_app database and select New Query.
Click this button to
access the Query
Options window.
SQL Server Fundamentals Troubleshooting
Page 246 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Troubleshooting (continued)
11
5. On the Query toolbar, click the Query Options button.
6. Under the Execution node, select Advanced.
7. Select the SET STATISTICS IO check box.
Note: For this example, we set this option so that each time we execute a query,
we will see statistics of I/O returned on the Messages tab. This will help when
tuning the queries.
8. Click OK to save the query.
Certified Student Course Curriculum - Version 2.0 Page 247
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Troubleshooting
Troubleshooting (continued)
12
9. Click the Query menu in the SQL Server Management Studio window.
10. Make sure Include Actual Execution Plan is selected. (An icon will display beside
it, indicating whether it is selected.)
Note: We are setting this option so that each time a query is executed, we can see
the execution plan that was used to execute the query. This is a plan generated as a
query is executed rather than an Estimated Execution Plan that can be produced
for some queries without the need to execute them. The option for an Estimated
Execution Plan is also on the Query menu.
11. In the main query window, type the following query
12. Execute the query by clicking the Execute button. Note the results returned in the
Results tab.
13. Click the Messages tab and review the output.
SQL Server Fundamentals Troubleshooting
Page 248 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Troubleshooting (continued)
13
14. In the example above, the output indicates that 300 logical page reads were
required to execute the query. Scan count can now be misleading and should be
ignored.
15. Click the Execution Plan tab and note the output.
In this example, the query is being executed by scanning the clustered index on
the table. That is estimated at 84% of the cost of the query and is a key aspect we
wish to avoid the need for. After the data has been obtained, an additional 16% of
the cost is consumed in sorting the output.
16. Switch to SQL Server Management Studio, expand the Databases node > expand
the mas500_app node > expand the Tables node > expand the dbo.tsmPostalCode
> then expand the Indexes node.
At this point notice that two indexes exist. The table is clustered on the CountryID
and PostalCode columns and there is a non-clustered index on the PostalCode and
CountryID columns. Neither of these indexes is a great solution for a query that
needs to locate rows for a particular StateID.
17. Hover over each of the operators in the execution plan and note the values in the
pop-up for each.
18. Note the warning about a Missing Index in the execution plan. Right-click in a
whitespace area of the plan and select Missing Index Details
Certified Student Course Curriculum - Version 2.0 Page 249
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Troubleshooting
Troubleshooting (continued)
14
19. Edit the new query window to resemble the following:
20. Execute the query by clicking the Execute button to create the new index.
21. Click back on the previous query window.
22. Execute the original query again by clicking the Execute button.
Note that the query returns the same data but quicker.
23. Click the Messages tab and note the reduction in logical page reads required to
execute the query.
24. Click the Execution Plan tab and note that the missing index hint has disappeared.
Note also that our newly created index is being chosen by the system. This is a
good indication that we've helped. If SQL Server ignores your new index, it's
probably the wrong index.
Note that the sort operation is still required.
While the Missing Index Dynamic Management View can provide good hints
about indexing structure, a trained DBA can often provide an index that will
outperform the hints.
25. Click back to the query window we used to create the index and modify its
contents to create another index.
26. Execute the query by clicking the Execute button to create the new index.
SQL Server Fundamentals Troubleshooting
Page 250 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Troubleshooting (continued)
15
27. Click back on the query window with the original query and re-execute it by
clicking the Execute button. Note the results on the Results tab:
We have not reduced the number of logical page reads. Small page read values
such as this are very hard to reduce and lower values would possibly be
misleading anyway. It would also be a waste of effort to try to go much further.
There will no doubt be bigger issues on the system to investigate.
28. Click the Execution Plan tab and review the output.
The sort operation is now unnecessary. Note that it's hard to read the name of the
index that has been used while in this view. Hover over the Index Seek operator
and note from the Object section that it is indeed our newly created index that has
been chosen.
29. Navigate to the list of indexes for this table in Object Explorer again, refresh the
list (right-click then Refresh) and note the new indexes. Delete the first version of
the index we created.
Note: A very common error is to create indexes that aren't going to be used and to
forget to delete them later. Unnecessary indexes can cause significant overhead to
transactional systems
Certified Student Course Curriculum - Version 2.0 Page 251
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Resources and References
Appendix C Resources and References
15
There are several SQL Server resources that are available to help you understand the
features and functionality, and expand your knowledge of SQL Server.
SQL Server Books Online
SQL Server Books Online is the comprehensive resource for anything relating to SQL
Server. These files are originally shipped with your SQL media, and installed when
you perform a typical installation type.
This online resource provides detailed documentation of all the SQL Server
functionality available. You can access the SQL Server Books Online at the following
location if you did not install it with SQL Server:
http://msdn.microsoft.com/en-us/library/ms130214.aspx
Some of the topics that are covered include:
How to Install SQL Server
SQL Server / Architecture
Administering SQL Server
Creating and Maintaining a Database
Optimizing the Database
XML and Internet Support
Transact-SQL reference
Building SQL Applications
Understanding Surface Area Configuration
Database Engine
Analysis Services
Integration Services
Reporting Services
Data Mining
SQL Server Fundamentals Resources and References
Page 252 Certified Student Course Curriculum - Version 2.0
Copyright 2010 Sage Software, Inc. All rights reserved.
Resources and References (continued)
16
If you installed SQL Server Books Online during your SQL Server installation,
Microsoft has updates you can download. It is recommended you install the updated
version to access the most recent information.
You can obtain the updates from www.microsoft.com/downloads and search for SQL
Server Books Online.
The Update version contains the following information:
Suggestions sent to Microsoft by customers using the feedback button available in
every topic of SQL Server Books Online.
Corrections of documentation errors reported after the release of the last update to
SQL Server Books Online.
New and updated error messages.
Additional SQL Resources on the Web
Microsoft SQL Server 2008- http://www.microsoft.com/sqlserver/2008/en/us/
Microsoft msdn library - http://msdn.microsoft.com/en-us/library/default.aspx
Microsoft Support - http://www.microsoft.com/sql/support/default.asp
For information about how to use Microsoft Update to identify updates for SQL
Server 2008, see the Microsoft Update website at
http://go.microsoft.com/fwlink/?LinkId=108409
Certified Student Course Curriculum - Version 2.0 Page 253
Copyright 2010 Sage Software, Inc. All rights reserved.
SQL Server Fundamentals Resources and References
Resources and References (continued)
17
References
msdn website articles at www.msdn.microsoft.com
- SQL Server Overview
- SQL Server Administration Tools
- Hardware and Software Requirements for Installing SQL Server 2008
- Introducing SQL Server Management Studio
- SQL Server Agent
- Activity Monitor
- How to: Create a Database (SQL Server Management Studio)
- Installing SQL Server 2008
- Maximum Capacity Specifications for SQL Server
Microsoft website articles at www.microsoft.com
- SQL Server 2008 Features Comparison
Sage/Microsoft Joint SQL Server Training - February 2010
By default, sample databases and sample code are not installed as part of SQL
Server Setup.
- To install sample databases and sample code for non-Express editions of SQL
Server 2008, see the CodePlex website at http://go.microsoft.com/fwlink/
?LinkId=87843
- To read about support for SQL Server sample databases and sample code for
SQL Server Express, see Databases and Samples Overview on the CodePlex
website at http://go.microsoft.com/fwlink/?LinkId=110391
For more information about late-breaking changes in this release of SQL Server,
see the latest readme file at http://go.microsoft.com/fwlink/?LinkId=100093