Sequence

 Sequence 

What is sequence :


sequence is a database object used to generate a series of unique numeric values. It is a generator of sequential integers that can be used as a column value during data insertion or for other purposes requiring unique numeric values.


Important note from Snowflake

Snowflake does not guarantee generating sequence numbers without gaps. The generated numbers consistently increase in value (or decrease in value if the step size is negative) but are not necessarily contiguous.


Create Sequence :

INSERT INTO (EMP_ID, NAME, JOB ,MANAGER, DOJ, SAL, COMM, DEPT)
select EMP_ID, NAME, JOB ,MANAGER, DOJ, SAL, COMM, DEPT from TRAINING.DEMO.MY_EMP_EXT_TBL where emp_id in (1111,1112) ;

describe table emp;
Create table with Sequence Number :
create or replace TABLE EMP (
    uniq_id INTEGER DEFAULT seq_01.nextval ,
EMP_ID NUMBER(38,0),
NAME VARCHAR(20),
JOB VARCHAR(20),
MANAGER VARCHAR(20),
DOJ VARCHAR(20),
SAL NUMBER(38,0),
COMM NUMBER(38,0),
DEPT NUMBER(38,0)
);

Inserting data into table where we are not using uniq_id still snowflake inserts uniq_id using seq

insert into emp (EMP_ID, NAME, JOB ,MANAGER, DOJ, SAL, COMM, DEPT)
select EMP_ID, NAME, JOB ,MANAGER, DOJ, SAL, COMM, DEPT from TRAINING.DEMO.MY_EMP_EXT_TBL where emp_id in (1111,1112) ;

describe table emp;

select * from emp;


Comments