title: Generic DELETE UPDATE with TRY CATCH
body: <p>I'm trying run this procedure with generic parameters.</p>
  
  <p>If I can't delete because some foreign key, it should update the row.</p>
  
  <p>But when I execute it, still running forever and don't complete the process, any Idea?</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER procedure [dbo].[stp_Batch_Registros_Desativados_Excluir]
      @table_name VARCHAR(100),   
      @id          int
  AS
  BEGIN 
          DECLARE @column VARCHAR(100),
                  @sql    VARCHAR(300);
  
         SET @column = (SELECT COLUMN_NAME 
                        FROM INFORMATION_SCHEMA.COLUMNS 
                          WHERE COLUMNPROPERTY(OBJECT_ID(TABLE_NAME),COLUMN_NAME,'IsIdentity') = 1 
                          AND TABLE_NAME = @table_name);
  
  
      BEGIN TRY    
           select @sql = 'DELETE ' + @table_name + ' WHERE ' + @column + ' = ' + CONVERT(VARCHAR,@id);     
           exec(@sql);    
      END TRY
  
      BEGIN CATCH
          select @sql = 'UPDATE ' + @table_name + ' SET fg_excluido = 2 WHERE ' + @column + ' = ' + CONVERT(VARCHAR,@id) ;
          exec(@sql);
      END CATCH;
  END
  </code></pre>