35
Module 3: SQL Server 2005 Administrative Tools

Module 3: SQL Server 2005 Administrative Tools

  • Upload
    nakia

  • View
    55

  • Download
    0

Embed Size (px)

DESCRIPTION

Module 3: SQL Server 2005 Administrative Tools. Overview. Using SQL Server Management Studio Using SQL Computer Manager Using the sqlcmd Utility Using the SQL Management Objects. Lesson: Using SQL Server Management Studio. What Is SQL Server Management Studio ? How to Register a Server - PowerPoint PPT Presentation

Citation preview

Page 1: Module 3:  SQL Server 2005 Administrative Tools

Module 3: SQL Server 2005

Administrative Tools

Page 2: Module 3:  SQL Server 2005 Administrative Tools

Overview

Using SQL Server Management Studio

Using SQL Computer Manager

Using the sqlcmd Utility

Using the SQL Management Objects

Page 3: Module 3:  SQL Server 2005 Administrative Tools

Lesson: Using SQL Server Management Studio

What Is SQL Server Management Studio?

How to Register a Server

What Is Object Explorer?

How to Execute Transact-SQL Queries

Demonstration: Using Transact-SQL in SQL Server Management Studio

What Is a SQL Server Management Studio Solution?

How to Create a SQL Server Management Studio Solution

Demonstration: Creating a Solution with Solution Explorer

Page 4: Module 3:  SQL Server 2005 Administrative Tools

Integrated management and development environment

Based on Visual Studio .NET

Incorporates functionality of Enterprise Manager, Query Analyzer, and Analysis Manager in previous releases

Used to manage relational databases, Analysis Services, Reporting Services, SQL Server Integration Services, andSQL Mobile databases

Includes tools for creating Transact-SQL, XMLA, MDX, and XQuery scripts

What Is SQL Server Management Studio?

Page 5: Module 3:  SQL Server 2005 Administrative Tools

How to Register a Server

Open Registered Servers windowOpen Registered Servers window11

Test the registered serverTest the registered server33Verify that the server appears under Registered ServersVerify that the server appears under Registered Servers44

Provide SQL Server instance detailsProvide SQL Server instance details22

Page 6: Module 3:  SQL Server 2005 Administrative Tools

What Is Object Explorer?

Window for browsing and managing objects

Object Explorer folders

Object Explorer buttons

Page 7: Module 3:  SQL Server 2005 Administrative Tools

How to Execute Transact-SQL Queries

Click New SQL Server QueryClick New SQL Server Query11

Click Execute and connect to SQL ServerClick Execute and connect to SQL Server33

Browse the resultsBrowse the results44

Type a Transact-SQL statementType a Transact-SQL statement22

Page 8: Module 3:  SQL Server 2005 Administrative Tools

Demonstration: Using Transact-SQL in SQL Server Management Studio

In this demonstration, you will see how to create and execute a query

Page 9: Module 3:  SQL Server 2005 Administrative Tools

What Is a SQL Server Management Studio Solution?

Collection of connections and queriesCollection of connections and queries

Project templatesProject templates

Page 10: Module 3:  SQL Server 2005 Administrative Tools

How to Create a SQL Server Management Studio Solution

Set the query properties Set the query properties 66

Type the Transact-SQL statementsType the Transact-SQL statements77

Create a new queryCreate a new query55

Save the projectSave the project88

Click File, New, ProjectClick File, New, Project11

Select the SQL Server Scripts templateSelect the SQL Server Scripts template22

Add a connectionAdd a connection33

Set the connection propertiesSet the connection properties44

Page 11: Module 3:  SQL Server 2005 Administrative Tools

Demonstration: Creating a Solution with Solution Explorer

In this demonstration, you will see how to create a SQL Server Management Studio solution

Page 12: Module 3:  SQL Server 2005 Administrative Tools

Lesson: Using SQL Computer Manager

What Is SQL Computer Manager?

Demonstration: Using SQL Computer Manager

How to Control Services

How to View and Change Service Properties

How to Manage Server Network Connectivity

How to Manage Client Network Connectivity

Page 13: Module 3:  SQL Server 2005 Administrative Tools

What Is SQL Computer Manager?

Console snap-in for managing SQL Server services and connectivity

Icons:

Services Server Network

Configuration Client Network

Configuration

Page 14: Module 3:  SQL Server 2005 Administrative Tools

Demonstration: Using SQL Computer Manager

In this demonstration, you will see how to:

Start SQL Computer Manager

View SQL Server 2005 Services

View Server Network Configuration

View Client Network Configuration

Page 15: Module 3:  SQL Server 2005 Administrative Tools

Start, stop, pause, resume, or restart a serviceStart, stop, pause, resume, or restart a service

How to Control Services

Open the SQL Computer ManagerOpen the SQL Computer Manager11

Click a service and select a service instanceClick a service and select a service instance33

Click the actionClick the action44

Expand ServicesExpand Services22

Page 16: Module 3:  SQL Server 2005 Administrative Tools

How to View and Change Service Properties

Click a service and select a service instanceClick a service and select a service instance11

Click Action, PropertiesClick Action, Properties22

Click the Service or Advanced tabClick the Service or Advanced tab33

Update the property and click OKUpdate the property and click OK44

Page 17: Module 3:  SQL Server 2005 Administrative Tools

How to Manage Server Network Connectivity

Enable or disable a server protocolEnable or disable a server protocol

View the Server Network Configuration nodeView the Server Network Configuration node11

Select an instance and a protocolSelect an instance and a protocol22

Click Action, Enable or Action, DisableClick Action, Enable or Action, Disable33

Change address parameters of a server protocolChange address parameters of a server protocol

Select an instance and a protocolSelect an instance and a protocol11

Click Action, PropertiesClick Action, Properties22

Modify settings and click OKModify settings and click OK33

Page 18: Module 3:  SQL Server 2005 Administrative Tools

How to Manage Client Network Connectivity

Enable or disable a client protocolEnable or disable a client protocol

View the Client Network Configuration nodeView the Client Network Configuration node11

Click Client Protocols and select a protocolClick Client Protocols and select a protocol22

Click Action, Enable or Action, DisableClick Action, Enable or Action, Disable33

Change parameters of a client protocolChange parameters of a client protocol

Click Client Protocols and select a protocolClick Client Protocols and select a protocol11

Click Action, PropertiesClick Action, Properties22

Modify settings and click OKModify settings and click OK33

Page 19: Module 3:  SQL Server 2005 Administrative Tools

Lesson: Using the sqlcmd Utility

What Is the sqlcmd Utility?

sqlcmd Command-Line Switches

How to Use the sqlcmd Utility Interactively

How to Execute Scripts Using the sqlcmd Utility

How to Use Variables With the sqlcmd Utility

Demonstration: Using Variables with the sqlcmd Utility

How to Use a Dedicated Administrator Connection

Page 20: Module 3:  SQL Server 2005 Administrative Tools

What Is the sqlcmd Utility?

Command-line tool for executing Transact-SQL statements and scripts

Uses OLE DB to run Transact-SQL batches Replaces osql

Enhancements over osql Variables Query server information Passes error information to calling environment Dedicated Administrator Connection Commands

Page 21: Module 3:  SQL Server 2005 Administrative Tools

sqlcmd Command-Line Switches

sqlcmd [-?] | [-L[c]] | [ { {-U login_id [-P password]} | –E } [-S server_name[\instance_name]] [-H wksta_name] [-d db_name] [-l time_out] [-t time_out] [-h headers] [-s col_separator] [-w column_width] [-a packet_size] [-e] [-I] [-c cmd_end] [-q "query"] [-Q "query"] [-m error_level] [-r [0 | 1]] [-i input_file[,file2…]] [-o output_file] [-p[1]] [-b] [-u] [-R] [-v var="value"[var="value"…]][-A] [-X[1]] [-V severitylevel] ]

sqlcmd [-?] | [-L[c]] | [ { {-U login_id [-P password]} | –E } [-S server_name[\instance_name]] [-H wksta_name] [-d db_name] [-l time_out] [-t time_out] [-h headers] [-s col_separator] [-w column_width] [-a packet_size] [-e] [-I] [-c cmd_end] [-q "query"] [-Q "query"] [-m error_level] [-r [0 | 1]] [-i input_file[,file2…]] [-o output_file] [-p[1]] [-b] [-u] [-R] [-v var="value"[var="value"…]][-A] [-X[1]] [-V severitylevel] ]

Page 22: Module 3:  SQL Server 2005 Administrative Tools

How to Use the sqlcmd Utility Interactively

Open a command prompt windowOpen a command prompt window11

Execute sqlcmdExecute sqlcmd22

Type Transact-SQL statements and sqlcmd commandsType Transact-SQL statements and sqlcmd commands33

Type GOType GO44

Type QUIT to close sqlcmdType QUIT to close sqlcmd55

Page 23: Module 3:  SQL Server 2005 Administrative Tools

Create a file containing Transact-SQL statements and sqlcmd commandsCreate a file containing Transact-SQL statements and sqlcmd commands11

Set the connection environment variablesSet the connection environment variables22

Invoke sqlcmd specifying –i and –o switchesInvoke sqlcmd specifying –i and –o switches33

Examine ERRORLEVELExamine ERRORLEVEL44

Examine the output fileExamine the output file55

How to Execute Scripts Using the sqlcmd Utility

Page 24: Module 3:  SQL Server 2005 Administrative Tools

How to Use Variables with the sqlcmd Utility

Create a sqlcmd script referencing variablesCreate a sqlcmd script referencing variables11

Invoke sqlcmd with –v to define the variables, or use environment variablesInvoke sqlcmd with –v to define the variables, or use environment variables22

sqlcmd –i MyScript.sql –o MyScript.out –v colname="name" tabname="sys.databases"

SELECT $(colname)FROM $(tabname)GO

SELECT $(colname)FROM $(tabname)GO

Page 25: Module 3:  SQL Server 2005 Administrative Tools

Demonstration: Using Variables with the sqlcmd Utility

In this demonstration, you will see how to:

Reference variables in a script

Instantiate variables from the command line

Use environment variables

Page 26: Module 3:  SQL Server 2005 Administrative Tools

How to Use a Dedicated Administrator Connection

Useful if the server hangs or is unresponsive

DAC runs using its own private scheduler

Connect using sqlcmd -AConnect using sqlcmd -A11

Diagnose the problem, terminate misbehaving connections, or shut down cleanlyDiagnose the problem, terminate misbehaving connections, or shut down cleanly22

1> CHECKPOINT2> GO1> SHUTDOWN WITH NOWAIT2> GOServer shut down by request

1> CHECKPOINT2> GO1> SHUTDOWN WITH NOWAIT2> GOServer shut down by request

Page 27: Module 3:  SQL Server 2005 Administrative Tools

Lesson: Using the SQL Management Objects

What Are the SQL Management Objects?

SMO Compared to SQL Server Distributed Management Objects

How to Create SMO Applications

How to Use SMO to Retrieve Server Information

How to Use SMO to Back Up a Database

Demonstration: Using SMO

Page 28: Module 3:  SQL Server 2005 Administrative Tools

What Are the SQL Management Objects?

JobServerJobServer

JobsJobs

JobJob

AlertsAlerts

AlertsAlerts

Shared SchedulesShared Schedules

Job ScheduleJob Schedule

ServerServer

ConnectionContextConnectionContext

DatabasesDatabases

DatabaseDatabase

AssembliesAssemblies

SqlAssemblySqlAssembly

FileGroupsFileGroups

FileGroupFileGroup

TablesTables

TableTable

Page 29: Module 3:  SQL Server 2005 Administrative Tools

SMO Compared with SQL Server Distributed Management Objects

SMO is a replacement for SQL-DMO

SQL-DMO retained only for backward compatibility

SMO uses an administrator-centric view

SMO and WMI

For monitoring and configuring servers

SMO Scripting

Scripter class provides enhanced scripting features

Page 30: Module 3:  SQL Server 2005 Administrative Tools

How to Create SMO Applications

Connect to the computer running SQL ServerConnect to the computer running SQL Server55

Open Visual Studio 2005Open Visual Studio 200511Create a new projectCreate a new project22Reference the SQL SMO assembliesReference the SQL SMO assemblies33Import the SMO namespacesImport the SMO namespaces44

Code your applicationCode your application66

Page 31: Module 3:  SQL Server 2005 Administrative Tools

How to Use SMO to Retrieve Server Information

Use the properties of the Server.Information classUse the properties of the Server.Information classEditionEdition IsClusteredIsClustered

IsSingleUserIsSingleUser LanguageLanguage

NetNameNetName OSVersionOSVersion

ParentParent PhysicalMemoryPhysicalMemory

PlatformPlatform ProcessorsProcessors

ProductProduct ProductLevelProductLevel

VersionStringVersionString

strEdition = myServer.Information.Edition

Page 32: Module 3:  SQL Server 2005 Administrative Tools

Practice: Using SMO

In this practice, you will see how to:

Create an SMO application

Retrieve server information

Page 33: Module 3:  SQL Server 2005 Administrative Tools

How to Use SMO to Back Up a Database

Call SqlBackup method of Backup objectCall SqlBackup method of Backup object55

Connect to SQL ServerConnect to SQL Server11

Declare and instantiate a Backup objectDeclare and instantiate a Backup object22

Set properties of Backup objectSet properties of Backup object33

Call Devices.Add method of Backup objectCall Devices.Add method of Backup object44

Page 34: Module 3:  SQL Server 2005 Administrative Tools

Demonstration: Using SMO

In this demonstration, you will see how to:

Use SMO to connect to a SQL Server

Use SMO to list databases on a SQL Server

Use SMO to create a new database

Page 35: Module 3:  SQL Server 2005 Administrative Tools

Lab 3: Administering SQL Server 2005

Exercise 1: Creating the Personnel Database

Exercise 2: Populating the Personnel Database

Exercise 3: Backing up the Personnel Database