Create a sequence named my_seq
create sequence my_seq
start with 1
increment by 1
Create a table in which one of the columns has a default value of my_seq
create table testing (col1 int, col2 int default next value for my_seq)
Now add some data to the table
insert into testing (col1)
select 34 union all
Select data from the table and see what col2 returns
select * from testing
Col2 returns unique numbers. It should be noted that if the sequence is used by many objects, the value may not be sequential i.e. some values may be used somewhere else.
This way we can use sequence object to generate unique numbers like an identity column
Did you like this post?
|subscribe via rss||subscribe via e-mail|
|print this post||follow me on twitter|