title: Is it possible to create SQL SERVER Function using transaction
body: <p>I have a simple script which basically do a lot of db operation. Now I have a requirement to upgrade the database for which I need to include a creation of function inside the same transaction.</p>
  
  <pre><code>BEGIN TRY --Start the Try Block..
  
      BEGIN TRANSACTION -- Start the transaction..
          -- HERE I need to add one function like
          IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FuctionTest]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
  DROP FUNCTION [dbo].[FuctionTest]
  GO
  CREATE FUNCTION FuctionTest 
  (   
      @inputVal int
  )
  RETURNS int
  AS
  BEGIN
      RETURN (Select Id from [dbo].[test] where Id=@inputVal)
  END
  
          UPDATE MyChecking SET Amount = Amount - @Amount
  
              WHERE AccountNum = @AccountNum
  
          UPDATE MySavings SET Amount = Amount + @Amount
  
              WHERE AccountNum = @AccountNum
  
      COMMIT TRAN -- Transaction Success!
  
  END TRY
  
  BEGIN CATCH
  
      IF @@TRANCOUNT &gt; 0
  
          ROLLBACK TRAN --RollBack in case of Error
  </code></pre>
  
  <p>How will I get this job done? I don't want to use a separate script to create the function.</p>