Create SQL Server job automatically

前端 未结 5 1496
北恋
北恋 2020-12-18 12:27

I am writing SQL Server deployment scripts which create SQL Server job automatically on a specific SQL Server server/instance. I have found that I can extract the sql statem

5条回答
  •  情歌与酒
    2020-12-18 12:36

    I was coming across the same problem today and how I tackle it is so simple Do the following

    1. Create a stored proc that creates the job with parameter @serverName nvarchar(128)

      Create Proc CreateAJob(@serverName nvarchar(128))
      
    2. Now easy, you can get the server name using the following

      Declare @serverName nvarchar(128)
      SELECT @servername=@@SERVERNAME
      
    3. Execute the stored proc to create your job

      EXEC CreateJob @serverName
      

    That is it.

    I am using visual studio db project and I did steps 2 and 3 int the postdeployment script

提交回复
热议问题