10
1.1 SQL Server 2005 管管管管管管管管管

1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

Embed Size (px)

Citation preview

Page 1: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

1.1 SQL Server 2005 管理工具介紹與使用

Page 2: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

Overview

Using SQL Server Management Studio

Using SQL Configuration Manager

Using the sqlcmd Utility

Page 3: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

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: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

Lesson: Using SQL Configuration Manager

What Is SQL Configuration Manager?

Demonstration: Using SQL Configuration 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 5: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

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 6: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

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 7: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

How to Use Variables with the sqlcmd Utility

SELECT $(colname)FROM $(tabname)GO

SELECT $(colname)FROM $(tabname)GO

Sqlcmd1>:Setvar DB adventureworksDW2>:connect R201001>backup database $(DB) to disk=‘c:\backup\$(DB).bak’2>go

Sqlcmd1>:Setvar DB adventureworksDW2>:connect R201001>backup database $(DB) to disk=‘c:\backup\$(DB).bak’2>go

Set sqlcmddbname=adventureworksSqlcmd1>:ListVar2>Quit

Set sqlcmddbname=adventureworksSqlcmd1>:ListVar2>Quit

Set colname=nameSet tabname=sys.databasesSqlcmd -i myscript.sql

Set colname=nameSet tabname=sys.databasesSqlcmd -i myscript.sql

Sqlcmd1>:ListVar2>Quit

Sqlcmd1>:ListVar2>Quit

Page 8: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

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 9: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

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 10: 1.1 SQL Server 2005 管理工具介紹與使用. Overview Using SQL Server Management Studio Using SQL Configuration Manager Using the sqlcmd Utility

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