Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 18th, 2008, 05:43 AM
Authorized User
 
Join Date: Feb 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to seed or increment NEWID() value

Hi all,

Newid() which creates a unique value of type uniqueidentifier.

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

For example:

create table cust(cust_id uniqueidentifier NOT NULL
DEFAULT newid(),cust_name 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!!!

101
102
103

I dont want to use IDENTITY column

Plz...can anyone help
 
Old February 18th, 2008, 01:49 PM
SQLScott's Avatar
Wrox Author
 
Join Date: Dec 2004
Posts: 338
Thanks: 0
Thanked 2 Times in 2 Posts
Default

No, but you could use NEWSEQUENTIALID(), which I wouldn't recommend because, per BOL: If privacy is a concern, do not use this function. It is possible to guess the value of the next generated GUID, and therefore access data associated with that GUID.

========================
Scott Klein
Author of:
Professional SQL Server 2005 XML
Professional WCF Programming: .NET Development with the Windows Communication Foundation
Professional LINQ
========================
 
Old February 19th, 2008, 10:53 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

By nature of the unique identifier (GUID) it is very "randomized". There is no way to increment it. If you want an incremental ID, use an identity column but note Scott's warning about privacy.

-Peter
peterlanoie.blog
 
Old February 19th, 2008, 01:24 PM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

Quote:
quote:Originally posted by planoie
 By nature of the unique identifier (GUID) it is very "randomized". There is no way to increment it. If you want an incremental ID, use an identity column but note Scott's warning about privacy.

-Peter
peterlanoie.blog
Not quite true in 2k5... there is a new sequential form of NEWID that can be used. You just can't seed it...

--Jeff Moden
 
Old February 19th, 2008, 02:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Jeff,

Is this new behavior for the existing Unique Identifier type or a new data type?

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Altering the Identity seed value g_vamsi_krish SQL Language 2 July 7th, 2006 12:58 AM
random seed? kiw Pro JSP 1 October 31st, 2004 03:27 PM
setting seed for autonumber in access dcary69 Access 1 October 5th, 2004 12:37 PM
NEWID() in Access Database Lucian Ion Dreamweaver (all versions) 1 November 10th, 2003 06:21 PM
NEWID() Lucian Ion Access ASP 1 November 10th, 2003 06:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.