title: Add a new column in table with a sequence - Oracle
body: <p>I have a table that has 60 million rows of data. I would like to introduce a new column say "id" for the table that is an auto incremented sequence.</p>
  
  <p>For example:</p>
  
  <pre><code>CREATE TABLE Persons (
      LastName varchar(255),
      FirstName varchar(255)
  );
  
  INSERT INTO Persons VALUES ('abc', 'def');
  INSERT INTO Persons VALUES ('abcd', 'ghi');
  
  CREATE SEQUENCE "PERSON_SEQUENCE" START WITH 1 INCREMENT BY 1;
  
  ALTER TABLE PERSONS ADD (PERSONID NUMBER);
  
  UPDATE persons SET personid = PERSON_SEQUENCE.NEXTVAL;
  </code></pre>
  
  <p>In the above sql statements, I am able to create a sequence then alter the table and update it.</p>
  
  <p>Since the amount of data I need to update is large.. I would like to perform this with as much low cost as possible.</p>
  
  <p>I am trying to do so something like this:</p>
  
  <pre><code>ALTER TABLE PERSONS ADD (PERSONID NUMBER DEFAULT(PERSON_SEQUENCE.NEXTVAL));
  </code></pre>
  
  <p>but the above does not work. Oracle throws me the below error:</p>
  
  <blockquote>
    <p>Error starting at line : </p>
    
    <p>1 in command - ALTER TABLE PERSONS ADD (PERSONID NUMBER
    DEFAULT(PERSON_SEQUENCE.NEXTVAL)) Error report -</p>
    
    <p><strong>ORA-00984:</strong> column not allowed here
    00984. 00000 -  "column not allowed here"
    *Cause:<br>
    *Action:</p>
  </blockquote>
  
  <p>However this works: </p>
  
  <pre><code>ALTER TABLE PERSONS ADD (PERSONID NUMBER DEFAULT(0));
  </code></pre>
  
  <p>Could some one help me with how I can achieve to alter a table (create a new column) and populate the column with a seq id both in a single sql. Thank you!</p>