How to seed or increment NEWID() value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sujathaeeshan
    New Member
    • Feb 2008
    • 22

    How to seed or increment NEWID() value

    Hi all,

    Newid() which creates a unique value of type uniqueidentifie r.

    Is there any possibolities for seeding or incrementing the NEWID() value.

    For example:

    create table cust(cust_id uniqueidentifie r NOT NULL
    DEFAULT newid(),cust_na me varchar(60) NOT NULL)

    For insertion example:
    INSERT cust (cust_id, contact_name) VALUES (newid(), ' ABC ' )
    INSERT cust (cust_id, contact_name) VALUES (newid(),' XYZ ' )
    INSERT cust (cust_id, contact_name) VALUES (newid(), ' PQR ' )
    If i am inserting more then one row detail NEWID() creates uniquevalue.

    But i want to increment the NEWID() value is that possible!!!

    Plz...can anyone help
  • docdiesel
    Recognized Expert Contributor
    • Aug 2007
    • 297

    #2
    Hi,

    do I understand you right, you'd like to get the first user uid=10000, the next one 10001 and so on? You could use a sequence:

    Code:
    create sequence
      seq_uid       as integer
      start with    10000
      increment by  1
      minvalue      10000
      no maxvalue
      no cache
      no cycle
    ;
    The next free uid value would be selectable by "select nextval for seq_uid from sysibm.sysdummy 1".

    Regards,

    Bernd

    Comment

    Working...