Search code examples
snowflake-cloud-data-platformsequencenextval

Adding a new column with nextval to an existing SNOWFLAKE database table


I am trying to insert a new column to an existing table in snowflake with nextval as similar to the supplierID in the below code (I did get_ddl on my stagingtable to get the below code). I added a new sequence and cloned with supplierID and when i did get ddl on the same table, its just showing contactID.nextval but not something like NUMBER(38,0) DEFAULT CLINIFYQA."ClinifyDB".ORGANIZATIONTYPEID.NEXTVAL.

Is it still correct or am I doing something wrong.

create or replace TABLE stagingtable (
    
    ORGANIZATIONID VARCHAR(200),
    COMPANYID VARCHAR(200),
    SUPPLIERID NUMBER(38,0) DEFAULT CLINIFYQA."ClinifyDB".ORGANIZATIONTYPEID.NEXTVAL)

Could someone please advice.]


Solution

  • ALTER TABLE stagingtable ADD COLUMN newColumn number DEFAULT CLINIFYQA."ClinifyDB".ORGANIZATIONTYPEID.NEXTVAL;
    

    https://docs.snowflake.com/en/sql-reference/sql/alter-table.html