microsoft sql server administration using ms sql server 2008 david henson...

122
Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson [email protected] www.certifiednetworks.com

Upload: heaven-sandridge

Post on 16-Dec-2015

222 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Microsoft SQL Server Administration Using MS SQL

Server 2008David Henson

[email protected]

www.certifiednetworks.com

Page 2: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Logistics

• Class Days: 3

• Class Hours: 9-5

• Notes/Handouts

• Demos

• Class website

Page 3: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Recommended Reading

• Microsoft SQL Server(TM) 2005 Administrator's Pocket Consultant

(Pro-Administrator's Pocket Consultant) • Microsoft Press

Page 4: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 1: Overview

• Course Outline

• Lab Setup

• Definitions

• Tools

• What is SQL Server

• SQL Language Basics

• SQL Server Network Integration

Page 5: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Course Outline – Day 1

• Module 1: Overview

• Module 2: Installation

• Module 3: Objects and Securables

• Module 4: Security And Principals

Page 6: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Course Outline – Day 2

• Module 5: Backup

• Module 6: Restore

Page 7: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Course Outline – Day 3

• Module 7: Web and Email Integration

• Module 8: Automation and Job Scheduling

• Module 9: Transferring Data

• Module 10: Replication

Page 8: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab Setup

• Windows 2003 Server

• SQL Server 2008– Standard, or Enterprise

• Computer Names

• IP Addresses

Page 9: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Definitions

• Transact SQL• DBA• Server• Client• Concurrency/Locks• Login• User• Role• Database

• SQL SMO(Formerly DMO)

• SQL Instance• Principal• Securable

Page 10: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Tools

• SQL Management Studio• Visual Studio .Net (2005/2008)• SQL Server Configuration Manager• Command Prompt

– SQLCMD– Ping, telnet, nslookup, net use

• Database Tuning Advisor• Full-FeaturedText Editor

– Notepad++(Free)– UltraEdit– Textpad

• Profiler

Page 11: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

What is SQL Server?

• Client Server Relational Database Operating System

• Windows Service That Manages Database Files, Security and Concurrency

Page 12: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Language Basics

• SELECT

• INSERT

• UPDATE

• DELETE

Page 13: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Server Network Integration

• Network oriented protocols– TCP/IP disabled on SQL Express by default

• DNS

• Windows Domain/Active Directory

• Firewalls

Page 14: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 1A – Tools

• In this instructor led lab, you will:– Preview SQL Management Studio– Preview Database Engine Tuning Advisor– Preview Profiler

Page 15: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 2: Installation

• Software Requirements

• Hardware Requirements

• SQL Server Versions

• Licensing

• Capacity Planning

• SQL Services

• Installation

Page 16: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Software Requirements

• Windows Server– 2000– 2003 or 2008

• Windows XP (Developer)

• Windows CE

Page 17: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Hardware Requirements

• Install Type Dependent– Express

• 192 MB RAM

– Standard/Enterprise• 512MB RAM

• 450 MB Typical Install

Page 18: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Server Versions

• DataCenter– Hardware/Software solution

• Enterprise• Standard• Developer• Workgroup• Express• Windows Mobile

Page 19: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Licensing

• Per Processor

• Per Server plus Device CALS

• Per Server plus User CALS

• SQL Server 2008 Express is free

Page 20: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Capacity Planning

• Drive Space

• CPU

• Memory

• I/O Subsystem

Page 21: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

I/O Subsystem

• RAID 0, 1, 5 or 10

• Logical Drive Structure

• Physical Drive Structure

• Considerations:– Performance– Ease and Cost of Management– Disaster Planning

Page 22: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Services

• Service Names:– SQL Server (MSSQLServer)– SQL Server Agent (MSSQLServer)– SQL Server Browser

• SQL Traffic director, allows Dedicated Admin Connection (DAC)

– SQL Server Integration Services• SQLIS.com

– SQL Server Fulltext Search– SQL Server Analysis Services– SQL Server Reporting Services

• Starting/Stopping

Page 23: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Service Accounts

• LocalSystem

• Local Account

• Domain Account

• Automatic Startup

Page 24: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Installation

• Options– Server– Instance– Client Tools Only

• Administrative Rights

• Instances

Page 25: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Online Demonstration: Installing an SQL Server instance

Page 26: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 3: Managing Objects

• Object Definition

• Creating Objects

• Altering Objects

• Dropping Objects

• MetaData

• Object Permissions

Page 27: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

What is an Object?

• Type Of Objects:– Table– View– Stored Procedure– Trigger– DataType– Function (UDF)– Index– Constraint

Page 28: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Synonyms

• Allows an alias for a securable

• New CREATE SYNONYM syntax

Page 29: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Creating Objects

• CREATE Statement

• Example:CREATE TABLE Customers(

CustomerID int identity,

CustomerEmail varchar(50)

)

Page 30: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Altering Objects

• ALTER Statement

• Example:ALTER TABLE Customers

ADD CustomerPhone varchar(40)

Page 31: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Dropping Objects

• DROP Statement

• Example:DROP TABLE Customers

Page 32: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Getting Metadata

• Information Schema

• Sysobjects table

• Sp_helptext

Page 33: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Setting Permissions

• GRANT Statement

• Example:GRANT SELECT

ON Customers

TO Public

Page 34: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 3A: Creating Objects

Page 35: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 3B: Altering Objects

Page 36: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 4: Security and Principals

Page 37: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Surface Area Configuration

• Best practice – reduce the “surface area” exposure of your system to minimum

• Off By Default – Microsoft .NET Framework,– SQL Service Broker Network Connectivity, and – HTTP connectivity in Analysis Services– Xp_cmdshell– Ad Hoc Remote Query– Database Mail– Native XML Web Service

• See Surface Area Configuration Tool

Page 38: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Levels of Security

• Login – Server Level

• User – Database Level

• Object – Permissions to Access Objects

• Application Security

• Network Access

• Encryption

Page 39: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Windows Workgroup Model

• Distributed Accounts– Each machine has locally maintained user

and group database

• Windows Server Not Required

Page 40: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Windows Domain Model

• Centralized Accounts– Active Directory is a single source for users

and groups

• Single Sign-On– Access all resources after logging in only

once

• Auditing

Page 41: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Active Directory

• Extension of the Domain Model– Leverages DNS Name Resolution– Better Security Protocols– Better Fault Tolerance– More Extensible– Group Policy

Page 42: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Logins

• Types:– Windows (Integrated)– SQL (Standard)

• Tools– SQL Management Studio– Scripts

Page 43: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Users

• Tools:– SQL Management Studio– Scripts

Page 44: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Roles

• Role Is A Group of users

• Purpose – Ease Permission Management

• Role Types:– Standard– Application Role

• Tools:– SQL Management Studio– Scripts

Page 45: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Permissions

• User Defined:– Action– Object Access– Object Execution

• Tools:– SQL Management Studio– Scripts

Page 46: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 4A: Creating Accounts

Page 47: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 4B: Creating Users and Groups

Page 48: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 4C: Permissions

Page 49: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 5: Backup

Page 50: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Reasons for Data Loss

• Accidental Update

• Hardware Failure

• Improper Application Design– Transactions Not Used

• Other User Error

• Intentional Distruction– Hackers– Viruses

Page 51: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Server Backup

• Online Backup– Users can access data during backup

• Types:– Full– Differential– Log

• COPY_ONLY option– Does not disturb normal backups, truncate logs, or

reset any flags

• Use of Filegroups

Page 52: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Increasing Backup Performance

• Set appropriate BLOCKSIZE parameter– -2048 good for cdrom stored backups– With default setting, restore uses buffered io

which is more flexible and slower

• Stripe backup devices

Page 53: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Restricted Activities During Backup

• Modifying Database Properties

• Autogrowth

• Managing Indexes

• Nonlogged Operations

Page 54: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Backup Statement

• Example:

BACKUP DATABASE Lab3A

To Disk=‘c:\Lab3A.bak’

WITH INIT, BLOCKSIZE=2048

Page 55: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Using SQL Management Studio

Page 56: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Backup Options

Page 57: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Database Recovery Model

• Property of a database

• Options:– Full– Bulk_Logged– Simple

• Affects log behavior

Page 58: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Backup Requirements

• System Databases:– Master – New Logins, change password– MSDB – Modifying or creating jobs

• User Databases:– Whenever data loss is unacceptable– At a rate when the cost(cash, downtime) of

restore is unacceptable

Page 59: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Operating A Standby Server

• Server 1-Log Backup Regularly

• Server 2-Log Restore with NoRecovery– Server 2 Database is read-only

• Server 2-Log Restore with Recovery– Used in case of catastrophic failure of Server1

Page 60: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Backup Devices

• Device = File

• Permanent object you can reference by name

• Example:BACKUP DATABASE Lab3A

TO DailyBackup

Page 61: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Tape Backup

• Must be attached locally to the SQL Server

• Some syntax is unique to tape media

• Must be recognized by Windows Backup as a SCSI tape device

Page 62: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Special Log Backups

• WITH Truncate_Only– Clears log, no backup file is created– Used to maintain log when no regular log backups occur

• WITH No_Truncate– Emergency use when data file not available

• WITH COPY_ONLY (new to SQL 2005)– Does not disturb normal backup flow or interrupt normal log

backup/restore process– Use on an ad-hoc basis before running potentially harmful

queries

Page 63: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Backup Strategies

• Weekly Full Backup

• Nightly Full Backup

• Variations of above with Differential and Log Backups

Page 64: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Best Practices

• Use Automation

• Test Your Backups

• Use Notification

• Use COPY_ONLY option as needed

• Understand the Business

• Keep Management Informed

Page 65: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 5A: Backup

Page 66: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 6: Restore

Page 67: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Restore Safety Features

• Restore will fail(or need override) if:– Backup file stored name does not match the

database name– Set of database files do not match– All necessary files are not available

Page 68: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Restore Database Statement

RESTORE DATABASE Lab6

FROM DISK=‘c:\Lab6.bak’

WITH RECOVERY

Page 69: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Restore Process

• Always backup the log first!

• Full

• Differential

• Log

• Recovery

Page 70: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Saving Space

• Maintain the log file

• Compress your backup files

Page 71: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Log Restore Options

• Stopping at a certain time

• Stopping at a named bookmark

Page 72: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Single Row Restore

• Use in case of accidental delete:– Restore to a temporary location– Enable identity inserts– Insert necessary rows

• Intimate knowledge of data structure required

Page 73: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Restoring Master

• Place server into single user mode

• Perform Restore

• Restart Server

Page 74: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Restoring Master with No Backup

• Rebuilm.exe utility creates brand new master, model, msdb

• Sp_attach_db plugs data files back in

Page 75: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Best Practices

• Backup the log at first sign of trouble

• Periodically test a restore

• Maintain enough working space

• Avoid the need to restore

• Backup system databases as required

Page 76: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 6A: Restore

Page 77: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 7: Web and Email Integration

Page 78: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Web Technologies

• Allow connection to SQL Server through HTTP

• Used for logging, collecting data, reporting, data transfer and admin functions

• Examples:– ASP, ASP.Net, Perl, CGI, Cold Fusion, JSP,

Java

Page 79: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Communication Process

Page 80: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Benefits of web integration

• Secure worldwide access

• No client deployment

• Remote access for administrative functions

Page 81: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Dangers of web access

• Misuse of data

• Data communication interception

• Hackers have a doorway to your network

Page 82: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Injection

• Malicious users leverage web input against SQL Server

• Examples:– Running server level commands– Changing the where clause…OR 1=1– Running DDL Commands– Reading ODBC Errors for data discovery

Page 83: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Protection from SQL injection

• Only use minimal priviledged account

• Pre-process all input

• Minimize direct SQL from web page by using Stored Procs and UDFs

Page 84: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

ASP Example

Page 85: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

ASP.Net Example

Page 86: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Email Notification• Allows asynchronous communication with SQL Server• Numerous techniques:

– Database Mail• New to SQL 2005• Easy to use smtp mail provider, easy setup

– CDONTS.Newmail • Provided as a .dll file with Windows 2000• Com Object

– CDO.Message• Provide with XP/Windows 2003• Com Object

– SQLMail • MAPI Client• Must be setup during a full moon

– Third party objects– .NET Framework mail objects

Page 87: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

CDONTS Object

Page 88: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

CDO Object

Page 89: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Database Mail

Page 90: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SQL Mail Setup

• Not recommended

• Requirements:– MAPI compliant mail server– MAPI client on SQL Server– SQL Service logged in as domain account– Domain account has mailbox available

Page 91: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 7A: Web/Email Integration

Page 92: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 8: Automation and Job Scheduling

Page 93: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Requirements

• SQLServerAgent service must be running

• Permissions on network or local resources

Page 94: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Automation Examples

• Nightly backup

• Nightly data transfer

• Hourly generation of web pages

• Detection of server problems:– Log 95% full

• Backup Log• Email Notification

Page 95: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Automation Components

• Job– Collection of steps, each step performing work

• Operator– Pointer to email account in Database Mail or SQL

Mail

• Alerts– Connection between a detected problem and a

job/operator

Page 96: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Jobs• Created with gui or with sp_add_job• May be scheduled• Comprised of Steps:

– Transact SQL– Operating System Commands– ActiveX (VBScript/Javascript)– Other (Replication, SSIS, Analysis Services)

• Retain history• Might have success/failure workflow• Can target multiple servers

Page 97: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Defining a Job Step

Page 98: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Operators

• An alias to a native email address of SQL Mail or Database Mail

• Net Send address also supported

• Operator Addresses– Email – business hours email address– Pager – after hours email address– Net send

• Failsafe Operator

Page 99: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Defining an Operator

Page 100: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Alerts

• Alert types– SQL Server Error– SQL Server Performance Condition– WMI Query

• Windows eventlog MUST trigger response

• Alert response is defined by admins– Execute Job– Send Notification

Page 101: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Defining An Alert

Page 102: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Proxies• Allow job steps to run with a different windows

login

Page 103: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 8A: Automation and Job Scheduling

Page 104: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 9: Data Transfer

Page 105: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Data Transfer

• Movement of data between systems

• One of the most common DBA functions

Page 106: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Data Transfer Examples

• Nightly download of sales data from all stores

• Quarterly catalog update for website• Order fulfillment

– Hourly transfer of order information to fulfillment center

– Hourly gathering of ship tracking information

• Movement of web data into accounting system

Page 107: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Data Transfer Techniques

• SSIS and Import-Export Wizard• Legacy DTS Package Support• BCP.EXE command line utility• Backup/Restore• Distributed Queries• Saving results from query analyzer• Web Page download• Bulk Insert Statement• Detach/Re-attach database files• Log Shipping• Select/Insert

Page 108: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

SSIS

• Import/Export Wizard

• Visual Studio Project

Page 109: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

BCP

• Command line utility

• Examples:Bcp northwind..products out c:\nwind.csv –w –t, -r/n –T

Bcp “select * from products” queryout c:\nwind.txt –c –t~ -r/n –Usa -P

Page 110: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Backup/Restore

• Simply compress, then transfer the backup file to the destination

• Clean up sysusers table after restore

Page 111: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Distributed queries

• Openquery/Openrowset/OpenXML

• SELECT INTO

• INSERT/SELECT

• Linked Servers

Page 112: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Query Analyzer

• Controlling saved results

• Output to text file

• Reading from different providers

Page 113: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Web page download

• Response Content type change

• Saving results to a file, then providing a link

• Job scheduler, results come through email

Page 114: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Bulk Insert

Page 115: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Detach/Reattach database files

• On database node:– Right click/all tasks/detach

• Clean up of sysusers not needed after re-attachment

Page 116: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 9A: Data Transfer

Page 117: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Module 10: Replication

Page 118: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Definitions

• Automatic transfer of data between locations

Page 119: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Replication Types

• Transactional– Only changes are copied across– Most efficient

• Merge– Two sources of read/write data– Most dangerous

• Snapshot– Data is removed, then re-created on a

schedule

Page 120: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Replication Models

• Central publisher/Distributer

• Central Subscriber/Multiple Publisher

• Multiple Publisher/Subscriber

Page 121: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Setup Tips

• Ensure box servers are logged in with a domain account

• Ensure the domain account is an admin on both boxes

• Ensure the domain account can map to c$

• Ensure the domain account can run queries against the other server

Page 122: Microsoft SQL Server Administration Using MS SQL Server 2008 David Henson dhenson@certifiednetworks.com

Lab 13A: Replication