title: Alter primary key sequence( 'Default' to 'Always') in DB2
body: <p>I have created the below table in DB2. Since the sequence is <code>GENERATED BY DEFAULT</code>, the primary key can be inserted in table(as the primary key is added after table creation with alter) and there is chance of duplicate values. The solution is to create the sequence by using <code>GENERATED BY ALWAYS</code>. Now I have data in table and I want to alter it from <code>GENERATED BY DEFAULT</code> to <code>GENERATED BY ALWAYS</code></p>
  
  <pre><code>  CREATE TABLE HW_COB.ILCCDS 
    ( 
                     CDS_IDENTITY FOR COLUMN CDSID NUMERIC(13, 0) GENERATED BY DEFAULT AS IDENTITY ( 
                     START WITH 1 INCREMENT BY 1 
                     NO MINVALUE NO MAXVALUE 
                     NO CYCLE NO ORDER 
                     CACHE 20 ) ,
  
  CODE_1 FOR COLUMN CDSCD1 CHAR(30),
  CODE_2 FOR COLUMN CDSCD2 CHAR(30) );
  ALTER TABLE HW_COB.ILCCDS ADD CONSTRAINT HW_COB.PK_CDS_IDENTITY PRIMARY KEY (CDS_IDENTITY);
  </code></pre>