title: SQL Syntax Error: Msg 156, 'Incorrect Syntax Near CREATE'
body: <p>I can't find the Syntax Error in the following Query:</p>
  
  <pre><code>USE [Contact Manager]
  GO
  -- Define the Procedure
  ALTER PROCEDURE [dbo].[sp_delete_Contact]
      @contactID INT
  AS
  BEGIN
      -- SET NOCOUNT OFF added enable Counting
      SET NOCOUNT OFF;
  
      -- Determine all Phone Numbers with a Single Link to the specified Contact
      CREATE TABLE #PhoneNumbers (phone_number INT NOT NULL PRIMARY KEY)
  
      INSERT #PhoneNumbers (phone_number)
          SELECT phone_number
          FROM Contact_PhoneNumber
          WHERE phone_number IN
          (
              SELECT phone_number
              FROM Contact_PhoneNumber
              GROUP BY phone_number
              HAVING COUNT(*) = 1
          )
          AND contact = @contactID
  
      -- Declare Loop Variables
      DECLARE @i int = 0
      DECLARE @count int = (SELECT COUNT(*) FROM #PhoneNumbers)
  
      -- Delete all Phone Numbers with a Single Link to the specified Contact
      WHILE @i &lt; @count
          EXEC sp_delete_PhoneNumber
          (
              SELECT phone_number, ROW_NUMBER()
                  OVER (ORDER BY phone_number) AS row_num
              FROM #PhoneNumbers
              WHERE row_num = @i
          )
  
          SET @i = @i + 1
      END
  
      -- Determine all Addresses with a Single Link to the specified Contact
      CREATE TABLE #Addresses ([address] INT NOT NULL PRIMARY KEY)
  
      INSERT #Addresses ([address])
          SELECT [address]
          FROM Contact_Address
          WHERE [address] IN
          (
              SELECT [address]
              FROM Contact_Address
              GROUP BY [address]
              HAVING COUNT(*) = 1
          )
          AND contact = @contactID
  
      -- Reset Loop Variables
      SET @i = 0
      SET @count = (SELECT COUNT(*) FROM #Addresses)
  
      -- Delete all Addresses with a Single Link to the specified Contact
      WHILE @i &lt; @count
          EXEC sp_delete_Address
          (
              SELECT [address], ROW_NUMBER()
                  OVER (ORDER BY [address]) AS row_num
              FROM #Addresses
              WHERE row_num = @i
          )
  
          SET @i = @i + 1
      END
  
      -- Determine all Emails with a Single Link to the specified Contact
      CREATE TABLE #Emails (email INT NOT NULL PRIMARY KEY)
  
      INSERT #Emails (email)
          SELECT email
          FROM Contact_Email
          WHERE email IN
          (
              SELECT email
              FROM Contact_Email
              GROUP BY email
              HAVING COUNT(*) = 1
          )
          AND contact = @contactID
  
      -- Reset Loop Variables
      SET @i = 0
      SET @count = (SELECT COUNT(*) FROM #Emails)
  
      -- Delete all Emails with a Single Link to the specified Contact
      WHILE @i &lt; @count
          EXEC sp_delete_Email
          (
              SELECT email, ROW_NUMBER()
                  OVER (ORDER BY email) AS row_num
              FROM #Emails
              WHERE row_num = @i
          )
  
          SET @i = @i + 1
      END
  
      -- Determine all Groups with a Single Link to the specified Contact
      CREATE TABLE #Groups ([group] INT NOT NULL PRIMARY KEY)
  
      INSERT #Groups ([group])
          SELECT [group]
          FROM Member
          WHERE [group] IN
          (
              SELECT [group]
              FROM Member
              GROUP BY [group]
              HAVING COUNT(*) = 1
          )
          AND contact = @contactID
  
      -- Reset Loop Variables
      SET @i = 0
      SET @count = (SELECT COUNT(*) FROM #Groups)
  
      -- Delete all Groups with a Single Link to the specified Contact
      WHILE @i &lt; @count
          EXEC sp_delete_Group
          (
              SELECT [group], ROW_NUMBER()
                  OVER (ORDER BY [group]) AS row_num
              FROM #Emails
              WHERE row_num = @i
          )
  
          SET @i = @i + 1
      END
  END
  </code></pre>
  
  <p>Any help with this would be greatly appreciated.</p>
  
  <p>The comments should let you know what I'm trying to do, but I'm pretty certain that the logic behind the code is solid. I just don't know where the syntax errors are.</p>
  
  <p>When I try to run the query to alter to stored procedure, I get the following errors:</p>
  
  <pre><code>Msg 156, Level 15, State 1, Procedure sp_delete_Contact, Line 81
  Incorrect syntax near the keyword 'CREATE'.
  Msg 156, Level 15, State 1, Procedure sp_delete_Contact, Line 113
  Incorrect syntax near the keyword 'CREATE'.
  Msg 156, Level 15, State 1, Procedure sp_delete_Contact, Line 143
  Incorrect syntax near the keyword 'END'.
  </code></pre>