title: Teradata rename table if exists
body: <p>I'm using Teradata. I'd like rename a table with a script sql and not using bteq, if a specific conditions is satisfied.</p>
  
  <p>In particular:</p>
  
  <p>if TABLE_A exists => rename table TABLE_B to TABLE_B_OLD</p>
  
  <p>In Sql Server:</p>
  
  <pre><code>IF OBJECT_ID('TABLE_A', 'U') IS NULL
   EXEC sp_rename 'TABLE_B', 'TABLE_B_OLD'; 
  </code></pre>
  
  <p>In Oracle:</p>
  
  <pre><code>DECLARE
          cnt NUMBER;
          BEGIN 
              select COUNT(*) INTO cnt from sys.user_tables where table_name = 'TABLE_A'
  
              IF cnt&gt;0 THEN
                  execute immediate 'rename table TABLE_B to TABLE_B_OLD';
              END IF;
          END;  
  </code></pre>
  
  <p>How can I made it with Teradata,</p>
  
  <p>Thanks </p>
  
  <p>Fabio</p>