How to Stop SSMS 2012 from scripting SPs using sp_executesql

前端 未结 4 1956
灰色年华
灰色年华 2021-02-18 15:34

I realise this is a very similar question to Stop SSMS from scripting SPs using sp_executesql?

However, they seem to have changed the behaviour with SSMS 2012.

I

4条回答
  •  Happy的楠姐
    2021-02-18 16:15

    The closest you can get to this functionality is to go under tools, options, SQL Server Object Explorer, Scripting, then set the Check for Object Existing to false.

    The drawback is that if you do this then drops and creates will always try to drop even if the object does not exist. The ideal solution would be a setting that allowed your script to look like the example below for creating Views, Procedures, and User-Defined Functions.

    /****** Object:  View [dbo].[vEmployees]    Script Date: 9/14/2012 9:18:57 AM ******/
    IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[vEmployees]'))
    DROP VIEW [dbo].[vEmployees]
    GO
    
    CREATE VIEW [dbo].[vEmployees]
    AS
        SELECT DISTINCT
            Employees.EmployeeID,
            FirstName,
            LastName
        from
            Employees
                JOIN Sales on Employees.EmployeeID=Sales.EmployeeID
    GO
    

    In short if the scripting engine thinks of the drop and create together in checking for object existance it does not need to put the condition on the create.

提交回复
热议问题