ssms2008 代码自动提示_使用 SSMS 的提示和技巧 - SQL Server Management Studio (SSMS) | Microsoft Docs...
使用 SQL Server Management Studio (SSMS) 的提示和技巧Tips and tricks for using SQL Server Management Studio (SSMS)
03/13/2018
本文內(nèi)容
本文介紹了一些使用 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
縮進(jìn)文本Indent your text
在對(duì)象資源管理器中篩選對(duì)象Filter objects in Object Explorer
訪問(wèn) SQL ServerSQL Server 錯(cuò)誤日志Access your SQL ServerSQL Server error log
查找 SQL ServerSQL Server 實(shí)例的名稱Find the name of your SQL ServerSQL Server instance
先決條件Prerequisites
若要測(cè)試本文提供的步驟,必須有 SQL Server Management StudioSQL Server Management Studio、對(duì) SQL Server 的訪問(wèn)權(quán)限,以及 AdventureWorks 數(shù)據(jù)庫(kù)。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. 系統(tǒng)不會(huì)執(zhí)行已注釋掉的文本。Text that is commented out is not executed.
打開(kāi) SQL Server Management StudioSQL Server Management Studio。Open SQL Server Management StudioSQL Server Management Studio.
連接到 SQL Server。Connect to your SQL server.
打開(kāi)“新建查詢”窗口。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
突出顯示文本的“更改數(shù)據(jù)庫(kù)”部分,然后選擇工具欄中的“注釋”按鈕 :Highlight the Alter Database portion of the text, and then select the Comment button on the toolbar:
選擇“執(zhí)行”運(yùn)行取消注釋的文本部分 。Select Execute to run the uncommented portion of the text.
突出顯示除“更改數(shù)據(jù)庫(kù)”命令之外的所有內(nèi)容,然后選擇“注釋”按鈕 :Highlight everything except for the Alter Database command, and then select the Comment button:
備注
注釋的文本的鍵盤快捷方式是 CTRL + K,CTRL + C 。The keyboard shortcut to comment text is CTRL + K, CTRL + C.
突出顯示文本的“更改數(shù)據(jù)庫(kù)”部分,然后選擇工具欄中的“取消注釋”按鈕以取消注釋 :Highlight the Alter Database portion of the text, and then select the Uncomment button to uncomment it:
備注
取消注釋的文本的鍵盤快捷方式是 CTRL + K,CTRL + U 。The keyboard shortcut to uncomment text is CTRL + K, CTRL + U.
選擇“執(zhí)行”運(yùn)行取消注釋的文本部分 。Select Execute to run the uncommented portion of the text.
縮進(jìn)文本Indent your text
可使用工具欄上的縮進(jìn)按鈕增加或減少文本的縮進(jìn)。You can use the indentation buttons on the toolbar to increase or decrease the indent of your text.
打開(kāi)“新建查詢”窗口。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
突出顯示文本的“更改數(shù)據(jù)庫(kù)”部分,然后選擇工具欄上的“增加縮進(jìn)”按鈕以向前移動(dòng)此文本 :Highlight the Alter Database portion of the text, and then select the Increase Indent button on the toolbar to move this text forward:
再次突出顯示文本的“更改數(shù)據(jù)庫(kù)”部分,然后選擇“減少縮進(jìn)”按鈕以向后移動(dòng)此文本 。Highlight the Alter Database portion of the text again, and then select the Decrease Indent button to move this text back.
在對(duì)象資源管理器中篩選對(duì)象Filter objects in Object Explorer
在具有多個(gè)對(duì)象的數(shù)據(jù)庫(kù)中,可以使用篩選功能來(lái)搜索特定表、視圖等。本節(jié)介紹如何篩選表,但可在對(duì)象資源管理器中的任何其他節(jié)點(diǎn)中使用以下步驟:In databases that have many objects, you can use filtering to search for specific tables, views, etc. This section describes how to filter tables, but you can use the following steps in any other node in Object Explorer:
連接到 SQL Server。Connect to your SQL server.
展開(kāi)“數(shù)據(jù)庫(kù)” > “AdventureWorks” > “表” 。Expand Databases > AdventureWorks > Tables. 此時(shí)將顯示數(shù)據(jù)庫(kù)中的所有表。All the tables in the database appear.
右鍵單擊“表”,然后選擇“篩選器” > “篩選器設(shè)置” :Right-click Tables, and then select Filter > Filter Settings:
在“篩選器設(shè)置”窗口中,可以修改以下某些篩選器設(shè)置 :In the Filter Settings window, you can modify some of the following filter settings:
按名稱篩選:Filter by name:
按架構(gòu)篩選:Filter by schema:
若要清除篩選器,請(qǐng)右鍵單擊“表”,然后選擇“刪除篩選器” 。To clear the filter, right-click Tables, and then select Remove Filter.
訪問(wèn) SQL Server 錯(cuò)誤日志Access your SQL Server error log
錯(cuò)誤日志是一個(gè)文件,其中包含 SQL ServerSQL Server 實(shí)例中所發(fā)生操作的相關(guān)詳細(xì)信息。The error log is a file that contains details about things that occur in your SQL ServerSQL Server instance. 可瀏覽和查詢 SSMS 中的錯(cuò)誤日志。You can browse and query the error login SSMS. 錯(cuò)誤日志是位于磁盤上的日志文件。The error log is a .log file that's located on your disk.
在 SSMS 中打開(kāi)錯(cuò)誤日志Open the error log in SSMS
連接到你的 SQL ServerSQL Server。Connect to your SQL ServerSQL Server.
展開(kāi)“管理” > “SQL Server 日志” 。Expand Management > SQL Server Logs.
右鍵單擊“當(dāng)前”錯(cuò)誤日志,然后選擇“查看 SQL Server 日志” :Right-click the Current error log, and then select View SQL Server Log:
在 SSMS 中查看查詢?nèi)罩綫uery the error log in SSMS
連接到 SQL Server。Connect to your SQL server.
打開(kāi)“新建查詢”窗口。Open a New Query window.
將以下 Transact-SQLTransact-SQL 代碼粘貼到查詢窗口:Paste the following Transact-SQLTransact-SQL code in your query window:
sp_readerrorlog 0,1,'Server process ID'
將單引號(hào)中的文本修改為要搜索的文本。Modify the text in the single quotes to text you want to search for.
執(zhí)行查詢?nèi)缓蟛榭唇Y(jié)果:Execute the query, and then review the results:
如果連接到 SQL Server,請(qǐng)查找錯(cuò)誤日志位置Find the error log location if you're connected to SQL Server
連接到你的 SQL ServerSQL Server。Connect to your SQL ServerSQL Server.
打開(kāi)“新建查詢”窗口。Open a New Query window.
將以下 Transact-SQLTransact-SQL 代碼粘貼到查詢窗口,然后選擇“執(zhí)行”:Paste the following Transact-SQLTransact-SQL code in your query window, and then select Execute:
SELECT SERVERPROPERTY('ErrorLogFileName') AS 'Error log file location'
結(jié)果將顯示文件系統(tǒng)中錯(cuò)誤日志的位置:The results show the location of the error log in the file system:
如果無(wú)法連接到 SQL Server,請(qǐng)查找錯(cuò)誤日志位置Find the error log location if you can't connect to SQL Server
你的 SQL ServerSQL Server 錯(cuò)誤日志的路徑可能有所不同,具體取決于你的配置設(shè)置。The path for your SQL ServerSQL Server error log can vary depending on your configuration settings. 可以在 SQL Server 配置管理器內(nèi)的啟動(dòng)參數(shù)中找到錯(cuò)誤日志位置的路徑。The path for the error log location can be found in the startup parameters within the SQL Server Configuration Manager. 請(qǐng)按照以下步驟來(lái)找到標(biāo)識(shí) SQL ServerSQL Server 錯(cuò)誤日志位置的相關(guān)啟動(dòng)參數(shù)。Follow the steps below to locate the relevant startup parameter identifying the location of your SQL ServerSQL Server error log. 你的路徑可能與以下指示的路徑有所不同 。Your path may vary from the path indicated below.
打開(kāi)“SQL Server 配置管理器”。Open SQL Server Configuration Manager.
展開(kāi)“服務(wù)” 。Expand Services.
右鍵單擊你的 SQL ServerSQL Server 實(shí)例,然后選擇“屬性”:Right-click your SQL ServerSQL Server instance, and then select Properties:
選擇“啟動(dòng)參數(shù)”選項(xiàng)卡 。Select the Startup Parameters tab.
在“現(xiàn)有參數(shù)”區(qū)域中,“-e”后面的路徑是錯(cuò)誤日志的位置 :In the Existing Parameters area, the path after "-e" is the location of the error log:
此位置中包含多個(gè)錯(cuò)誤日志文件。There are several error log files in this location. 當(dāng)前錯(cuò)誤日志的文件名以 *.log 結(jié)尾。The file name that ends with *.log is the current error log file. 以前的日志文件的文件名以數(shù)字結(jié)尾。File names that end with numbers are previous log files. 每次重新啟動(dòng) SQL Server 時(shí)都會(huì)創(chuàng)建一個(gè)新日志。A new log is created every time the SQL server restarts.
在記事本中打開(kāi) errorlog.log 文件。Open the errorlog.log file in Notepad.
查找 SQL Server 實(shí)例名稱Find SQL Server instance name
在連接到 SQL Server 之前和之后,有幾個(gè)選項(xiàng)可用于查找 SQL ServerSQL Server 的名稱。You have a few options for finding the name of your SQL server before and after you connect to SQL ServerSQL Server.
連接到 SQL Server 之前Before you connect to SQL Server
Follow the steps to locate the SQL Server error log on disk. 你的路徑可能與下圖中的路徑有所不同。Your path may vary from the path in the image below.
在記事本中打開(kāi) errorlog.log 文件。Open the errorlog.log file in Notepad.
搜索文本“服務(wù)器名稱是” 。Search for the text Server name is.
單引號(hào)中列出的所有內(nèi)容都是將連接到的 SQL ServerSQL Server 實(shí)例的名稱:Whatever is listed in the single quotes is the name of the SQL ServerSQL Server instance that you'll be connecting to:
名稱的格式為 HOSTNAME\INSTANCENAME。The format of the name is HOSTNAME\INSTANCENAME. 如果只看到了主機(jī)名,然后已安裝了默認(rèn)實(shí)例,則實(shí)例名稱是 MSSQLSERVER。If you see only the host name, then you've installed the default instance and your instance name is MSSQLSERVER. 連接到默認(rèn)實(shí)例時(shí),只需輸入主機(jī)名以連接到 SQL Server。When you connect to a default instance, the host name is all you need to enter to connect to your SQL server.
連接到 SQL Server 時(shí)When you're connected to SQL Server
連接到 SQL ServerSQL Server 時(shí),可在三個(gè)位置找到服務(wù)器名稱:When you're connected to SQL ServerSQL Server, you can find the server name in three locations:
服務(wù)器名稱將在“對(duì)象資源管理器”中列出:The name of the server is listed in Object Explorer:
服務(wù)器名稱將在查詢窗口中列出:The name of the server is listed in the Query window:
服務(wù)器名稱將在“屬性”中列出 。The name of the server is listed in Properties.
在“視圖”菜單上,選擇“屬性窗口” :In the View menu, select Properties Window:
如果連接到別名或可用性組偵聽(tīng)程序If you're connected to an alias or Availability Group listener
如果連接到別名或可用性組偵聽(tīng)程序,則將在“對(duì)象資源管理器”和“屬性”中顯示該信息。If you're connected to an alias or to an Availability Group listener, that information appears in Object Explorer and Properties. 在這種情況下,SQL ServerSQL Server 名稱可能不是顯而易見(jiàn)的,并且必須進(jìn)行查詢:In this case, the SQL ServerSQL Server name might not be readily apparent, and must be queried:
連接到 SQL Server。Connect to your SQL server.
打開(kāi)“新建查詢”窗口。Open a New Query window.
將以下 Transact-SQLTransact-SQL 代碼粘貼到窗口中:Paste the following Transact-SQLTransact-SQL code in the window:
select @@Servername
查看查詢結(jié)果,確定連接到的 SQL ServerSQL Server 實(shí)例的名稱:View the results of the query to identify the name of the SQL ServerSQL Server instance you're connected to:
后續(xù)步驟Next steps
熟悉 SSMS 的最好方式是進(jìn)行實(shí)踐演練。The best way to get acquainted with SSMS is through hands-on practice. 這些教程 和操作說(shuō)明 文章可幫助你使用 SSMS 的各種功能。These tutorial and how-to articles help you with various features available within SSMS. 這些文章教你如何管理 SSMS 組件,以及如何查找常用功能。These articles teach you how to manage the components of SSMS and how to find the features that you use regularly.
總結(jié)
以上是生活随笔為你收集整理的ssms2008 代码自动提示_使用 SSMS 的提示和技巧 - SQL Server Management Studio (SSMS) | Microsoft Docs...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 渣女网名121个
- 下一篇: 完全复制一个dict_Redis主从复制