使用 SQL Server Management Studio 中的範本Use templates in SQL Server Management Studio

本教學課程將介紹 SQL Server Management Studio (SSMS) 中可用的預先建立 Transact-SQL (T-SQL) 範本。This tutorial introduces you to the prebuilt Transact-SQL (T-SQL) templates that are available in SQL Server Management Studio (SSMS). 在此文章中,您將學會如何:In this article, you learn how to:

PrerequisitesPrerequisites

若要完成本教學課程,您需要 SQL Server Management Studio 和 SQL Server 存取權。To complete this tutorial, you need SQL Server Management Studio and access to a SQL server.

使用範本瀏覽器Use Template Browser

在本節中,您將學習如何尋找及使用範本瀏覽器。In this section, you learn how to locate and use Template Browser.

  1. 開啟 SQL Server Management Studio。Open SQL Server Management Studio.

  2. 在 [檢視] 功能表中,選取 [範本瀏覽器] (Ctrl+Alt+T):In the View menu, select Template Browser (Ctrl+Alt+T):

    開啟範本瀏覽器

    您可以在範本瀏覽器底部查看最近使用過的範本。You can see recently used templates at the bottom of the template browser.

  3. 展開您感興趣的節點。Expand the node you're interested in. 以滑鼠右鍵按一下範本,然後選取 [開啟] 。Right-click the template, and then select Open:

    開啟範本

    您也可以按兩下範本名稱以開啟它。You can also double-click the template name to open it.

  4. 隨即開啟 [新增查詢] 視窗。A new query window opens. 已填入 T-SQL 指令碼。The T-SQL script is already populated.

  5. 修改範本以符合您的需求,然後選取 [執行] 來執行查詢:Modify the template to suit your needs, and then select Execute to run the query:

    建立資料庫範本

編輯現有範本Edit an existing template

您也可以在範本瀏覽器內編輯現有範本。You can also edit existing templates in Template Browser.

  1. 在範本瀏覽器中,移至您想要使用的範本。In Template Browser, go to the template you want to work with.

  2. 以滑鼠右鍵按一下範本,然後選取 [編輯] :Right-click the template, and then select Edit:

    編輯範本

  3. 在開啟的查詢視窗中,進行您想要的變更。In the query window that opens, make the changes that you want to make.

  4. 選取 [檔案] > [儲存] (Ctrl + S) 以儲存範本。To save the template, select File > Save (Ctrl+S).

  5. 關閉查詢視窗。Close the query window.

  6. 重新開啟範本。Reopen the template. 您的編輯應該會出現。Your edits should appear.

在磁碟上找出範本Locate templates on disk

開啟範本時,您可以找出磁碟上的範本。When a template is open, you can locate the templates that are on disk.

  1. 在範本瀏覽器中選取範本,然後選取 [編輯] 。In Template Browser, select a template, and then select Edit.

  2. 以滑鼠右鍵按一下 [查詢標題] ,然後選取 [開啟所屬資料夾] 。Right-click Query Title, and then select Open Containing Folder. 總管應該會開啟範本儲存在磁碟上的位置:The explorer should open where the templates are stored on disk:

    磁碟上的範本

建立新的範本Create a new template

您也可以在範本瀏覽器中建立新的範本。You can also create a new template in Template Browser. 下列步驟示範如何建立新的資料夾,然後在該資料夾內建立一個新範本。The following steps show you how to create a new folder, and then create a new template in that folder. 您也可以使用這些步驟,在現有的資料夾中建立自訂範本。You can also use these steps to create a custom template in an existing folder.

  1. 開啟範本瀏覽器。Open Template Browser.

  2. 以滑鼠右鍵按一下 [SQL Server 範本] ,然後選取 [新增] > [資料夾] 。Right-click SQL Server Templates, and then select New > Folder.

  3. 將此資料夾命名為自訂範本Name this folder Custom Templates:

    建立自訂範本資料夾

  4. 以滑鼠右鍵按一下新建立的 [自訂範本] 資料夾,然後選取 [新增] > [範本] 。Right-click the newly created Custom Templates folder, and then select New > Template. 輸入您的範本名稱:Enter a name for your template:

    建立自訂範本

  5. 以滑鼠右鍵按一下您建立的範本,然後選取 [編輯] 。Right-click the template you created, and then select Edit. 隨即開啟 [新增查詢] 視窗。The New Query Window opens.

  6. 輸入您想要儲存的 T-SQL 文字。Enter the T-SQL text that you want to save.

  7. 在 [檔案] 功能表中,選取 [儲存] 。In the File menu, select Save.

  8. 關閉現有查詢視窗,然後開啟您的新自訂範本。Close the existing query window, and then open your new custom template.

後續步驟Next steps

熟悉 SSMS 的最佳方式是實際練習。The best way to get acquainted with SSMS is through hands-on practice. 這些「教學課程」 與「操作方式」 文章可協助您使用 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.