Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 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 August 15th, 2004, 07:05 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Ok Hal, I see what you mean. I think my confusion was that I was making the assumption that others do such insertion tasks similar to the way I do them, which is one of two ways:

Open Connection
Insert Row
...
Request @@IDENTITY
Close Connection

    OR

Open Connection
Insert Row; Request @@IDENTITY;
Close Connection


I suppose your scenario is possible if you perform one action, then close the connection, then open again (getting another connection from the pool) and attempt to get the identity value.
 
Old August 16th, 2004, 10:09 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

Peter you ment
Open Connection
Insert Row;
Close Connection
.......
//here maybe another user inserts another row and @@IDENTITY will get a wrong answer
Open Connection
Request @@IDENTITY;
Close Connection

--------------------------------------------
Mehdi.:)
 
Old August 16th, 2004, 12:14 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

No, I meant what I posted. What I posted is the way I assumed other people do their database calls when they add records. If you use the techniques that I posted, you *shouldn't* encounter the problem we are discussing. Only when you close the connection then reopen it should you ever encounter this problem.
 
Old August 16th, 2004, 02:06 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,101
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Keep in mind- the OLD way that @IDENTITY worked, it returned the last row - on any connection.. I got into the habbit of generating my own keys then- and that's just the way I am used to. I know MSFT "fixed" the problem.. I just don't use it.


Hal Levy
Web Developer, PDI Inc.

NOT a Wiley/Wrox Employee
 
Old September 30th, 2004, 07:51 AM
Authorized User
 
Join Date: Sep 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Lalit_Pratihari
Default

Hi,

For AutoIncrement IDENTITY, IDENTITY SEED is a very good option.

Thanks,

Lalit
Life Means More... ;)
 
Old October 1st, 2004, 05:51 AM
Friend of Wrox
 
Join Date: Sep 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Anantsharma Send a message via Yahoo to Anantsharma
Default

If u r sure that ur Primary key is Numeric/Number.. type then Identity is the best option. However u will face some hidden issues with Identity colum in future and solutions ar there for those as well. I would be better to discuss with us later if u face prob and can't solve. U should study a little about Identity colum related and consideration. U will enjoy that.

If ur PK colum is not a number type data container, I suggest u use some user defined function to generate and use stored procedure if its of ur interest.

Good luk.


B. Anant





Similar Threads
Thread Thread Starter Forum Replies Last Post
auto increment primary key jcuga SQL Language 2 June 3rd, 2007 09:04 AM
How to auto increment primary key method SQL Server 2000 5 May 24th, 2005 03:25 PM
How to Auto Generate ID (Primary Key) SQL Database havering SQL Server ASP 1 December 9th, 2004 05:33 AM
How to Auto Generate ID (Primary Key) SQL database havering SQL Server 2000 9 December 1st, 2004 10:38 AM
auto increment primary key-compile error junemo Oracle 2 June 16th, 2004 08:53 AM





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