title: Teradata identity column and "Duplicate unique prime key error in dbname.tablename"
body: <p>I created a table using the below definition for a Teradata identity column:</p>
  
  <pre>
        ID INTEGER GENERATED BY DEFAULT AS IDENTITY
             (START WITH 1 
              INCREMENT BY 1 
              MINVALUE 0 
              MAXVALUE 100000000 
              NO CYCLE),
  ----
        UNIQUE PRIMARY INDEX ( ID )
  </pre>
  
  <p>For several months, the ID column has been working properly, automatically generating a unique value for the column.  Over the past month, however, ELMAH has been <em>intermittently</em> reporting the following exception from our .NET 4.0 ASP.NET app:</p>
  
  <p><code>Teradata.Client.Provider.TdException: [Teradata Database] [2801] Duplicate unique prime key error in DATABASENAME.TABLENAME.</code></p>
  
  <p>I was able to replicate it by opening SQL Assistant and inserting a bunch of records into the table with raw SQL.  As expected, most of the time it would insert successfully, but other times it would throw the above exception.</p>
  
  <p>It appears that this error is occuring because Teradata is trying to generate a value for this column that it has previously generated.</p>
  
  <p>Does anyone have any idea how to get to the bottom of what's happening?  At the very least, I'd like some way to debug the issue a bit deeper.</p>