title: SQL Server succeedes creating a stored procedure that invokes a NON-EXISTING function
body: <p>Tested on SQL Server 2017. If I create a procedure (either in SSMS or sqlcmd) containing a static SQL command referencing a <strong>non-existing function</strong>:</p>
  <pre><code>CREATE PROCEDURE mytest
  AS
  BEGIN
      DECLARE @tableVar TABLE(FIELD_1 INT, FIELD_2 VARCHAR(10))
  
      -- I am referencing a function that does not exist
      INSERT @tableVar 
          SELECT * FROM dbo.I_DO_NOT_EXISTS()
  END
  GO
  </code></pre>
  <p>Return message is:</p>
  <blockquote>
  <p>Commands completed successfully.</p>
  </blockquote>
  <p>This is quite an odd behaviour!</p>
  <p>Only when I try to run <code>mytest</code> I get the error:</p>
  <pre><code>exec dbo.mytest
  </code></pre>
  <blockquote>
  <p>Msg 208, Level 16, State 1, Procedure dbo.mytest, Line 10 [Batch Start Line 16]<br />
  Invalid object name 'dbo.I_DO_NOT_EXISTS'.</p>
  </blockquote>
  <p>While if I try to compile a procedure calling a non-existing function with <code>exec</code>:</p>
  <pre><code>CREATE PROCEDURE mytest
  AS
  BEGIN
      -- I am executing a function that does not exist
      EXEC dbo.I_DO_NOT_EXISTS
  END
  GO
  </code></pre>
  <p>I get a warning <strong>at compile time</strong></p>
  <blockquote>
  <p>The module 'mytest' depends on the missing object 'dbo.I_DO_NOT_EXISTS'. The module will still be created; however, it cannot run successfully until the object exists.</p>
  </blockquote>
  <p>The latter response seems the correct approach to me.</p>
  <p>Is there any option to enforce existence checks on functions referenced by SQL commands?</p>