6 0
Read Time:2 Minute, 10 Second

 ROW Numbers : SEQUENCE object and IDENTITY property use to generate a sequence of numeric values in an ascending order. Generating Sequences with Snowflake is straight forward like other Databases such as Oracle, While the value in an identity column created by the server.

However, being same in functionality, there are several differences among Row Numbers i.e. the IDENTITY property and SEQUENCE object.

1: SYNTACTICAL Difference:

start = 1 
comment = 'this sequence will be used to generate employee IDs';
create or replace table employees(row_number integer identity(100,1),
                     employee_id number,
                     salary number,
                     Age number);
Sequence Example:

2 : Association:

SEQUENCE object are define by the user and can be share by multiple tables since is it is not tie to any table.

IDENTITY property ties to a particular table and cannot be shared among multiple tables since it is a table column property.

Identity and Sequence

3 : Value Generation:

However, In order to generate the next IDENTITY value, it is must we should insert a new row into the table.

On the other hand, the next VALUE for a SEQUENCE object can simply be generated using the SEQ.NEXTVAL clause with the sequence object.


For instance, There is no alternative to get the next value for the IDENTITY property tied to the row_number column of employees_IDEN table, except by inserting a new row in the table. On the other hand, the value for a SEQUENCE object can be incremented without inserting a row into a table. Execute the following script:

select empid.nextval

4 : Value Reset:

IDENTITY property cannot reset to its initial value. In contrast, the value for the SEQUENCE object can reset by recreating the Sequences. Traditionally CYCLE parameter is not available in Snowflake like SQL/ORACLE.

Auto Increment and Identity:

Similarly, Auto Increment is a function that operates on numeric data types. Hence, It automatically generates sequential numeric values every time that a record inserts into a table for a field defined as auto increment.

Column constraints AUTO_INCREMENT and IDENTITY are synonyms that associate a column with a sequence. This sequence automatically increments the column value as new rows adds to the table.

You define an AUTO_INCREMENT/IDENTITY column in a table as follows:

Auto Increment
CREATE TABLE table-name...
  (column-name {AUTO_INCREMENT | IDENTITY} [(args)], ...)

AUTO_INCREMENT/IDENTITY sequences are owned by the table in which they are defined, and do not exist outside that table. Unlike named sequences, you cannot manage an AUTO_INCREMENT/IDENTITY sequence with ALTER SEQUENCE

Average Rating

5 Star
4 Star
3 Star
2 Star
1 Star

Leave a Reply

Your email address will not be published. Required fields are marked *