使用 SQL Server Management Studio (SSMS) 的提示和技巧Tips and tricks for using SQL Server Management Studio (SSMS)
03/13/2018
本文内容
本文介绍了一些使用 SQL Server Management StudioSQL Server Management Studio (SSMS) 的提示和技巧。This article gives you some tips and tricks for using SQL Server Management StudioSQL Server Management Studio (SSMS). 本文介绍如何:This article shows you how to:
注释/取消注释 Transact-SQL (T-SQL) 文本Comment/uncomment your Transact-SQL (T-SQL) text
缩进文本Indent your text
在对象资源管理器中筛选对象Filter objects in Object Explorer
访问 SQL ServerSQL Server 错误日志Access your SQL ServerSQL Server error log
查找 SQL ServerSQL Server 实例的名称Find the name of your SQL ServerSQL Server instance
先决条件Prerequisites
若要测试本文提供的步骤,必须有 SQL Server Management StudioSQL Server Management Studio、对 SQL Server 的访问权限,以及 AdventureWorks 数据库。To test out the steps provided in this article, you need SQL Server Management StudioSQL Server Management Studio, access to a SQL server, and an AdventureWorks database.
注释/取消注释 T-SQL 代码Comment/uncomment your T-SQL code
可使用工具栏中的“注释”按钮注释和取消注释部分文本 。You can comment and uncomment portions of your text by using the Comment button on the toolbar. 系统不会执行已注释掉的文本。Text that is commented out is not executed.
打开 SQL Server Management StudioSQL Server Management Studio。Open SQL Server Management StudioSQL Server Management Studio.
连接到 SQL Server。Connect to your SQL server.
打开“新建查询”窗口。Open a New Query window.
将以下 Transact-SQLTransact-SQL 代码粘贴到文本窗口。Paste the following Transact-SQLTransact-SQL code in your text window.
USE master
GO
-- Drop the database if it already exists
IF EXISTS (
SELECT name
FROM sys.databases
WHERE name = N'TutorialDB'
)
DROP DATABASE TutorialDB
GO
CREATE DATABASE TutorialDB
GO
ALTER DATABASE [TutorialDB] SET QUERY_STORE=ON
GO
突出显示文本的“更改数据库”部分,然后选择工具栏中的“注释”按钮 :Highlight the Alter Database portion of the text, and then select the Comment button on the toolbar:
选择“执行”运行取消注释的文本部分 。Select Execute to run the uncommented portion of the text.
突出显示除“更改数据库”命令之外的所有内容,然后选择“注释”按钮 :Highlight everything except for the Alter