LogScriptStart.sql 599 B

1234567891011121314151617181920212223
  1. CREATE PROCEDURE [dbo].[LogScriptStart]
  2. @serverName NVARCHAR(1023)
  3. AS
  4. DECLARE @rowId INT = NULL
  5. BEGIN TRANSACTION
  6. -- Get the row from the Servers table
  7. DECLARE @serverId INT
  8. SELECT @serverId = [Id] FROM [Servers] s WHERE s.ServerName = @serverName
  9. -- Return null if there isn't a row in the server table for this
  10. IF @serverId = NULL RETURN NULL
  11. -- Add a row to the instances table to log this script as 'running'
  12. INSERT INTO Instances (StartTime, ServerId, IsActive)
  13. VALUES (GETUTCDATE(), @serverId, 1)
  14. -- Return the new Id for the script to use
  15. SELECT SCOPE_IDENTITY()
  16. COMMIT