2016-04-29 72 views
0

當我按在SQL Server Management Studio中(SSMS)新建查詢,根據下面的圖片:如何在SSMS中每次按「新查詢」時加載腳本?

enter image description here

我想在一個新的選項卡下面的腳本。 會這樣嗎?

USE AdventureWorks2012; 
GO 

-- SET XACT_ABORT ON will render the transaction uncommittable 
-- when the constraint violation occurs. 
SET XACT_ABORT ON; 

BEGIN TRY 
    BEGIN TRANSACTION; 

    ------------------------------------------------------ 




    ------------------------------------------------------ 
    COMMIT TRANSACTION; 
END TRY 
BEGIN CATCH 
    -- Test XACT_STATE for 0, 1, or -1. 
    -- If 1, the transaction is committable. 
    -- If -1, the transaction is uncommittable and should 
    --  be rolled back. 
    -- XACT_STATE = 0 means there is no transaction and 
    --  a commit or rollback operation would generate an error. 

    -- Test whether the transaction is uncommittable. 
    IF (XACT_STATE()) = -1 
    BEGIN 
     PRINT 'The transaction is in an uncommittable state.' + 
       ' Rolling back transaction.' 
     ROLLBACK TRANSACTION; 
    END; 

    -- Test whether the transaction is active and valid. 
    IF (XACT_STATE()) = 1 
    BEGIN 
     PRINT 'The transaction is committable.' + 
       ' Committing transaction.' 
     COMMIT TRANSACTION; 
    END; 
END CATCH; 
GO 

在下面的鏈接上有一個非常類似的問題,但它不適用於我。 SSMS 2014

MSSQL Server Management Studio (SSMS) 2005 New Query Template

+1

你確定該文件已保存?它可能受到保護。它爲我通過修改此文件(對於SSMS2014):C:\ Program Files文件(x86)\ Microsoft SQL Server \ 120 \ Tools \ Binn \ ManagementStudio \ SqlWorkbenchProjectItems \ Sql \ SQLFile.sql –

+0

@PeterHenell斑點上它工作!問題是我將它保存在C:\ Program Files而不是C:\ Program Files(x86) –

+0

我將把問題留作參考。 –

回答

1

我不知道這是確定在這裏做,但我使用的代碼片段爲這樣的東西。您可以使用一個免費的發生器,例如https://snippetsgen.codeplex.com/ 並將它們保存在代碼片段管理器(或Ctr + K,ctr + B)下。然後通過快捷方式訪問它們(對於我來說,它是Ctr + K,Ctr + X)。我在這裏扔了很多經常被查詢的東西。

相關問題