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 January 20th, 2007, 04:11 PM
Registered User
 
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default concurency

i have found this case of concurency during my study to database subject i try to test this case but there is no
result because i have only one computer,


user1:
insert into Sale(money) value (1000) run at 12:12:12 pm
set id = @@identity
insert into Transaction(Transaction_Id,Account) value (id,1000)

user2:
insert into Sale(money) value (1000) run at 12:12:12 pm
set id = @@identity
insert into Transaction(Transaction_Id,Account) value (id,1000)

Note :- Sale have two column (Sale_Id with identity property set to true and money)
and Transaction have two column (Transaction_Id,Account)

1-is it possible to occur, if it is occur does a primary key constraint violation occur and if a primary key constraint violation doesn't occur what is the
value of id into both user's application?
2-is it need to put insert statement inside
Transaction Block to Prevent the above case or database engin manage this case?

 
Old January 21st, 2007, 12:33 AM
Friend of Wrox
 
Join Date: Oct 2006
Posts: 475
Thanks: 0
Thanked 9 Times in 9 Posts
Default

First, don't use @@IDENTITY because if triggers that do inserts on tables with identity colums fire, you WILL get the wrong values back. Use SCOPE_IDENTITY() instead.

Second, User1 and User2 will always get different numbers back and they will accurately represent the row each inserted. It is not possible to get a PK violation on the Transaction table with the code you posted even if a thousand users are using it.

--Jeff Moden





Similar Threads
Thread Thread Starter Forum Replies Last Post
Concurency using JSM with EJB 1.1 (Book example) hvilleneuve J2EE 0 May 25th, 2004 08:17 PM





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