Sequence In Snowflake | What is Sequence In Snowflake

Other Blogs

Image could not load

Image by unsplash

Snowflake Sequence

Snowflake में "sequence" एक database object है जो automatic numeric values generate करता है। ये values एक particular order में increment करते हैं।

Sequences commonly primary keys या unique identifiers generate करने के लिए use किये जाते हैं।

Snowflake Sequence Syntax

CREATE [ OR REPLACE ] SEQUENCE [ IF NOT EXISTS ] <name>
  [ WITH ]
  [ START [ WITH ] [ = ] <initial_value> ]
  [ INCREMENT [ BY ] [ = ] <sequence_interval> ]
  [ { ORDER | NOORDER } ]
  [ COMMENT = '<string_literal>' ]

Snowflake Sequence Example

नीचे दिए गए example में increase_by_one नाम से जो हर बार 1 से value increase करेगा।

-- create sequence CREATE OR REPLACE SEQUENCE increase_by_one START = 1 INCREMENT = 1; -- show all sequences show sequences;

increase value get करने के लिए sequence की nextval property होती है जो हर बार incremental value return करेगी।

SELECT increase_by_one.nextval;

output

+---------+
| NEXTVAL |
|---------|
|       1 |
+---------+

Run again

SELECT increase_by_one.nextval;

Output

+---------+
| NEXTVAL |
|---------|
|       2 |
+---------+

increase_by_one.nextval का use करके किसी table के auto increment field में values insert करते time use कर सकते हो।

single query में आप multiple call भी कर सकते हैं।

SELECT increase_by_one.nextval a, increase_by_one.nextval b, increase_by_one.nextval c;

output

+----+----+----+
| a  | b  | c  |
+----+----+----+
| 3  | 4  | 5  |
+----+----+----+

Snowflake Alter Sequence

किसी existing sequence को modify करने के लिए ALTER SEQUENCE statement का use किया जाता है।

Syntax

ALTER SEQUENCE [ IF EXISTS ] <name> RENAME TO <new_name>

ALTER SEQUENCE [ IF EXISTS ] <name> [ SET ] [ INCREMENT [ BY ] [ = ] <sequence_interval> ]

ALTER SEQUENCE [ IF EXISTS ] <name> SET
  [ { ORDER | NOORDER } ]
  [ COMMENT = '<string_literal>' ]

Alter Sequence Example

ALTER SEQUENCE increase_by_one RENAME TO increaseByOne;

Snowflake Drop Sequence

किसी existing sequence को modify करने के लिए DROP SEQUENCE statement का use किया जाता है।

Syntax

DROP SEQUENCE [ IF EXISTS ] <name> [ CASCADE | RESTRICT ]

Example

DROP SEQUENCE IF EXISTS increaseByOne;

I Hope , आपको Snowflake में SEQUENCE के बारे में अच्छे से समझ आया होगा।

Recent Blogs

Loading ...

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 4.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook

Your Thought ?

Please wait . . .

    0 Comment(s) found !