8/10/2019 sqladmin2008
1/122
Microsoft SQL ServerAdministration Using MS SQL
Server 2008David Henson
www.certifiednetworks.com
mailto:[email protected]:[email protected]8/10/2019 sqladmin2008
2/122
Logistics
Class Days: 3
Class Hours: 9-5
Notes/Handouts Demos
Class website
8/10/2019 sqladmin2008
3/122
Recommended Reading
Microsoft SQL Server(TM) 2005 Administrator'sPocket Consultant(Pro-Administrator's Pocket Consultant)
Microsoft Press
http://www.amazon.com/gp/reader/0735621071/ref=sib_dp_pt/104-7437819-91607268/10/2019 sqladmin2008
4/122
Module 1: Overview
Course Outline
Lab Setup
Definitions Tools
What is SQL Server
SQL Language Basics SQL Server Network Integration
8/10/2019 sqladmin2008
5/122
Course OutlineDay 1
Module 1: Overview
Module 2: Installation
Module 3: Objects and Securables Module 4: Security And Principals
8/10/2019 sqladmin2008
6/122
Course OutlineDay 2
Module 5: Backup
Module 6: Restore
8/10/2019 sqladmin2008
7/122
Course OutlineDay 3
Module 7: Web and Email Integration
Module 8: Automation and Job Scheduling
Module 9: Transferring Data Module 10: Replication
8/10/2019 sqladmin2008
8/122
Lab Setup
Windows 2003 Server
SQL Server 2008
Standard, or Enterprise Computer Names
IP Addresses
8/10/2019 sqladmin2008
9/122
Definitions
Transact SQL
DBA
Server
Client Concurrency/Locks
Login
User Role
Database
SQL SMO(FormerlyDMO)
SQL Instance
Principal Securable
8/10/2019 sqladmin2008
10/122
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
8/10/2019 sqladmin2008
11/122
What is SQL Server?
Client Server Relational DatabaseOperating System
Windows Service That Manages DatabaseFiles, Security and Concurrency
8/10/2019 sqladmin2008
12/122
SQL Language Basics
SELECT
INSERT
UPDATE DELETE
8/10/2019 sqladmin2008
13/122
SQL Server Network Integration
Network oriented protocols
TCP/IP disabled on SQL Express by default
DNS
Windows Domain/Active Directory
Firewalls
8/10/2019 sqladmin2008
14/122
Lab 1ATools
In this instructor led lab, you will:
Preview SQL Management Studio
Preview Database Engine Tuning Advisor
Preview Profiler
8/10/2019 sqladmin2008
15/122
Module 2: Installation
Software Requirements
Hardware Requirements
SQL Server Versions Licensing
Capacity Planning
SQL Services Installation
8/10/2019 sqladmin2008
16/122
Software Requirements
Windows Server
2000
2003 or 2008
Windows XP (Developer)
Windows CE
8/10/2019 sqladmin2008
17/122
Hardware Requirements
Install Type Dependent
Express
192 MB RAM
Standard/Enterprise
512MB RAM
450 MB Typical Install
8/10/2019 sqladmin2008
18/122
SQL Server Versions
DataCenter Hardware/Software solution
Enterprise
Standard
Developer
Workgroup
Express
Windows Mobile
8/10/2019 sqladmin2008
19/122
Licensing
Per Processor
Per Server plus Device CALS
Per Server plus User CALS
SQL Server 2008 Express is free
8/10/2019 sqladmin2008
20/122
Capacity Planning
Drive Space
CPU
Memory I/O Subsystem
8/10/2019 sqladmin2008
21/122
I/O Subsystem
RAID 0, 1, 5 or 10
Logical Drive Structure
Physical Drive Structure
Considerations:
Performance Ease and Cost of Management
Disaster Planning
8/10/2019 sqladmin2008
22/122
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
8/10/2019 sqladmin2008
23/122
Service Accounts
LocalSystem
Local Account
Domain Account
Automatic Startup
8/10/2019 sqladmin2008
24/122
Installation
Options
Server
Instance
Client Tools Only
Administrative Rights
Instances
8/10/2019 sqladmin2008
25/122
Online Demonstration: Installing anSQL Server instance
8/10/2019 sqladmin2008
26/122
Module 3: Managing Objects
Object Definition
Creating Objects
Altering Objects Dropping Objects
MetaData
Object Permissions
8/10/2019 sqladmin2008
27/122
What is an Object?
Type Of Objects: Table
View
Stored Procedure Trigger
DataType
Function (UDF) Index
Constraint
8/10/2019 sqladmin2008
28/122
Synonyms
Allows an alias for a securable
New CREATE SYNONYM syntax
8/10/2019 sqladmin2008
29/122
Creating Objects
CREATE Statement
Example:CREATE TABLE Customers(
CustomerID int identity,
CustomerEmail varchar(50)
)
8/10/2019 sqladmin2008
30/122
Altering Objects
ALTER Statement
Example:ALTER TABLE Customers
ADD CustomerPhone varchar(40)
8/10/2019 sqladmin2008
31/122
Dropping Objects
DROP Statement
Example:DROP TABLE Customers
8/10/2019 sqladmin2008
32/122
Getting Metadata
Information Schema
Sysobjects table
Sp_helptext
8/10/2019 sqladmin2008
33/122
Setting Permissions
GRANT Statement
Example:GRANT SELECT
ON Customers
TO Public
8/10/2019 sqladmin2008
34/122
Lab 3A: Creating Objects
8/10/2019 sqladmin2008
35/122
Lab 3B: Altering Objects
8/10/2019 sqladmin2008
36/122
Module 4: Security and Principals
8/10/2019 sqladmin2008
37/122
Surface Area Configuration
Best practicereduce the surface area exposure ofyour 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
8/10/2019 sqladmin2008
38/122
Levels of Security
LoginServer Level
UserDatabase Level
ObjectPermissions to Access Objects
Application Security
Network Access Encryption
8/10/2019 sqladmin2008
39/122
Windows Workgroup Model
Distributed Accounts
Each machine has locally maintained userand group database
Windows Server Not Required
8/10/2019 sqladmin2008
40/122
Windows Domain Model
Centralized Accounts
Active Directory is a single source for usersand groups
Single Sign-OnAccess all resources after logging in only
once
Auditing
8/10/2019 sqladmin2008
41/122
Active Directory
Extension of the Domain Model
Leverages DNS Name Resolution
Better Security Protocols
Better Fault Tolerance
More Extensible
Group Policy
8/10/2019 sqladmin2008
42/122
Logins
Types:
Windows (Integrated)
SQL (Standard)
Tools
SQL Management Studio
Scripts
8/10/2019 sqladmin2008
43/122
Users
Tools:
SQL Management Studio
Scripts
8/10/2019 sqladmin2008
44/122
Roles
Role Is A Group of users
PurposeEase Permission Management
Role Types: Standard
Application Role
Tools: SQL Management Studio
Scripts
8/10/2019 sqladmin2008
45/122
Permissions
User Defined:
Action
Object Access
Object Execution
Tools:
SQL Management Studio
Scripts
8/10/2019 sqladmin2008
46/122
Lab 4A: Creating Accounts
L b 4B C ti U d
8/10/2019 sqladmin2008
47/122
Lab 4B: Creating Users andGroups
8/10/2019 sqladmin2008
48/122
Lab 4C: Permissions
8/10/2019 sqladmin2008
49/122
Module 5: Backup
8/10/2019 sqladmin2008
50/122
Reasons for Data Loss
Accidental Update
Hardware Failure
Improper Application Design
Transactions Not Used
Other User Error
Intentional Distruction Hackers
Viruses
8/10/2019 sqladmin2008
51/122
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, orreset any flags
Use of Filegroups
8/10/2019 sqladmin2008
52/122
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
8/10/2019 sqladmin2008
53/122
Restricted Activities During Backup
Modifying Database Properties
Autogrowth
Managing Indexes
Nonlogged Operations
8/10/2019 sqladmin2008
54/122
Backup Statement
Example:
BACKUP DATABASE Lab3A
To Disk=c:\Lab3A.bak
WITH INIT, BLOCKSIZE=2048
8/10/2019 sqladmin2008
55/122
Using SQL Management Studio
8/10/2019 sqladmin2008
56/122
Backup Options
8/10/2019 sqladmin2008
57/122
Database Recovery Model
Property of a database
Options:
Full
Bulk_Logged
Simple
Affects log behavior
8/10/2019 sqladmin2008
58/122
Backup Requirements
System Databases:
MasterNew Logins, change password
MSDBModifying or creating jobs
User Databases:
Whenever data loss is unacceptable
At a rate when the cost(cash, downtime) of
restore is unacceptable
8/10/2019 sqladmin2008
59/122
8/10/2019 sqladmin2008
60/122
Backup Devices
Device = File
Permanent object you can reference byname
Example:BACKUP DATABASE Lab3A
TO DailyBackup
8/10/2019 sqladmin2008
61/122
Tape Backup
Must be attached locally to the SQLServer
Some syntax is unique to tape media
Must be recognized by Windows Backupas a SCSI tape device
8/10/2019 sqladmin2008
62/122
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
8/10/2019 sqladmin2008
63/122
Backup Strategies
Weekly Full Backup
Nightly Full Backup
Variations of above with Differential and
Log Backups
8/10/2019 sqladmin2008
64/122
Best Practices
Use Automation
Test Your Backups
Use Notification
Use COPY_ONLY option as needed
Understand the Business
Keep Management Informed
8/10/2019 sqladmin2008
65/122
Lab 5A: Backup
8/10/2019 sqladmin2008
66/122
Module 6: Restore
8/10/2019 sqladmin2008
67/122
Restore Safety Features
Restore will fail(or need override) if:
Backup file stored name does not match thedatabase name
Set of database files do not matchAll necessary files are not available
8/10/2019 sqladmin2008
68/122
Restore Database Statement
RESTORE DATABASE Lab6
FROM DISK=c:\Lab6.bak
WITH RECOVERY
8/10/2019 sqladmin2008
69/122
Restore Process
Always backup the log first!
Full
Differential
Log
Recovery
8/10/2019 sqladmin2008
70/122
Saving Space
Maintain the log file
Compress your backup files
8/10/2019 sqladmin2008
71/122
Log Restore Options
Stopping at a certain time
Stopping at a named bookmark
8/10/2019 sqladmin2008
72/122
Single Row Restore
Use in case of accidental delete: Restore to a temporary location
Enable identity inserts
Insert necessary rows
Intimate knowledge of data structurerequired
8/10/2019 sqladmin2008
73/122
Restoring Master
Place server into single user mode
Perform Restore
Restart Server
8/10/2019 sqladmin2008
74/122
Restoring Master with No Backup
Rebuilm.exe utility creates brand newmaster, model, msdb
Sp_attach_db plugs data files back in
8/10/2019 sqladmin2008
75/122
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
8/10/2019 sqladmin2008
76/122
Lab 6A: Restore
Module 7: Web and Email
8/10/2019 sqladmin2008
77/122
Module 7: Web and EmailIntegration
8/10/2019 sqladmin2008
78/122
Web Technologies
Allow connection to SQL Server throughHTTP
Used for logging, collecting data,
reporting, data transfer and adminfunctions
Examples:
ASP, ASP.Net, Perl, CGI, Cold Fusion, JSP,Java
C i i P
8/10/2019 sqladmin2008
79/122
Communication Process
8/10/2019 sqladmin2008
80/122
D f b
8/10/2019 sqladmin2008
81/122
Dangers of web access
Misuse of data
Data communication interception
Hackers have a doorway to your network
SQL I j ti
8/10/2019 sqladmin2008
82/122
SQL Injection
Malicious users leverage web inputagainst SQL Server
Examples:
Running server level commands
Changing the where clauseOR 1=1
Running DDL Commands
Reading ODBC Errors for data discovery
P t ti f SQL i j ti
8/10/2019 sqladmin2008
83/122
Protection from SQL injection
Only use minimal priviledged account
Pre-process all input
Minimize direct SQL from web page byusing Stored Procs and UDFs
ASP E l
8/10/2019 sqladmin2008
84/122
ASP Example
ASP N t E l
8/10/2019 sqladmin2008
85/122
ASP.Net Example
E il N tifi ti
8/10/2019 sqladmin2008
86/122
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
CDONTS Obj t
8/10/2019 sqladmin2008
87/122
CDONTS Object
CDO Obj t
8/10/2019 sqladmin2008
88/122
CDO Object
Database Mail
8/10/2019 sqladmin2008
89/122
Database Mail
SQL M il S t
8/10/2019 sqladmin2008
90/122
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
Lab 7A: Web/Email Integration
8/10/2019 sqladmin2008
91/122
Lab 7A: Web/Email Integration
Module 8: Automation and Job
8/10/2019 sqladmin2008
92/122
Scheduling
Requirements
8/10/2019 sqladmin2008
93/122
Requirements
SQLServerAgent service must be running
Permissions on network or local resources
Automation Examples
8/10/2019 sqladmin2008
94/122
Automation Examples
Nightly backup
Nightly data transfer
Hourly generation of web pages
Detection of server problems:
Log 95% full
Backup Log
Email Notification
Automation Components
8/10/2019 sqladmin2008
95/122
Automation Components
Job Collection of steps, each step performing work
Operator Pointer to email account in Database Mail or SQL
Alerts Connection between a detected problem and a
job/operator
Jobs
8/10/2019 sqladmin2008
96/122
Jobs Created with gui or with sp_add_job
May be scheduled Comprised of Steps:
Transact SQL
Operating System CommandsActiveX (VBScript/Javascript)
Other (Replication, SSIS, Analysis Services)
Retain history Might have success/failure workflow
Can target multiple servers
Defining a Job Step
8/10/2019 sqladmin2008
97/122
Defining a Job Step
Operators
8/10/2019 sqladmin2008
98/122
Operators
An alias to a native email address of SQL Mail orDatabase Mail
Net Send address also supported
Operator Addresses Emailbusiness hours email address Pagerafter hours email address
Net send
Failsafe Operator
Defining an Operator
8/10/2019 sqladmin2008
99/122
Defining an Operator
Alerts
8/10/2019 sqladmin2008
100/122
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
Defining An Alert
8/10/2019 sqladmin2008
101/122
Defining An Alert
Proxies
8/10/2019 sqladmin2008
102/122
Allow job steps to run with a different windows
login
Lab 8A: Automation and Job
8/10/2019 sqladmin2008
103/122
Scheduling
Module 9: Data Transfer
8/10/2019 sqladmin2008
104/122
Module 9: Data Transfer
Data Transfer
8/10/2019 sqladmin2008
105/122
Data Transfer
Movement of data between systems One of the most common DBA functions
Data Transfer Examples
8/10/2019 sqladmin2008
106/122
Data Transfer Examples
Nightly download of sales data from allstores
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 accountingsystem
Data Transfer Techniques
8/10/2019 sqladmin2008
107/122
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
SSIS
8/10/2019 sqladmin2008
108/122
SSIS
Import/Export Wizard
Visual Studio Project
BCP
8/10/2019 sqladmin2008
109/122
BCP
Command line utility
Examples:
Bcp northwind..products outc:\nwind.csv w t, -r/n T
Bcp select * from products
queryout c:\nwind.txt c t~ -r/nUsa -P
Backup/Restore
8/10/2019 sqladmin2008
110/122
Backup/Restore
Simply compress, then transfer the backupfile to the destination
Clean up sysusers table after restore
Distributed queries
8/10/2019 sqladmin2008
111/122
Distributed queries
Openquery/Openrowset/OpenXML SELECT INTO
INSERT/SELECT
Linked Servers
Query Analyzer
8/10/2019 sqladmin2008
112/122
Query Analyzer
Controlling saved results
Output to text file
Reading from different providers
Web page download
8/10/2019 sqladmin2008
113/122
Web page download
Response Content type change
Saving results to a file, then providing a
link
Job scheduler, results come through email
Bulk Insert
8/10/2019 sqladmin2008
114/122
Bulk Insert
Detach/Reattach database files
8/10/2019 sqladmin2008
115/122
Detach/Reattach database files
On database node: Right click/all tasks/detach
Clean up of sysusers not needed after re-attachment
Lab 9A: Data Transfer
8/10/2019 sqladmin2008
116/122
Lab 9A: Data Transfer
Module 10: Replication
8/10/2019 sqladmin2008
117/122
Module 10: Replication
Definitions
8/10/2019 sqladmin2008
118/122
Definitions
Automatic transfer of data betweenlocations
Replication Types
8/10/2019 sqladmin2008
119/122
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
Replication Models
8/10/2019 sqladmin2008
120/122
Replication Models
Central publisher/Distributer
Central Subscriber/Multiple Publisher
Multiple Publisher/Subscriber
Setup Tips
8/10/2019 sqladmin2008
121/122
Setup Tips
Ensure box servers are logged in with adomain 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
Lab 13A: Replication
8/10/2019 sqladmin2008
122/122
Lab 13A: Replication