Click here to Skip to main content
15,889,858 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

ALTER TRIGGER [PIP_ENTRYINSERT]  ON dbo.PIP_Entry
   
	AFTER INSERT AS 
	
	UPDATE PIP_ENTRY SET pipcode = (SELECT 'PIP'++CONVERT(VARCHAR,MAX(pipcode1)+1) FROM PIP_ENTRY) where pipcode =''
	UPDATE PIP_ENTRY SET pipcode1 = (SELECT MAX(pipcode1)+1 FROM PIP_ENTRY) where pipcode1 = 0

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


The Above trigger i have used to increment row value when ever data is inserted (ie., After insert trigger). Here i have a problem when i use this trigger in web application. The actual problem is number of user's inserting data at same time then it is not working it is not able to generate running number for all the users. Because this trigger works like row-identity.
So i need solution for this post.
Thanks in advance
Posted
Updated 8-Feb-12 19:24pm
v2

1 solution

Your question is like this person :

Multi-instances accessing to the same database and primary key conflict problem?[^]

Transactions will solve your problem.
 
Share this answer
 
Comments
rajrprk 9-Feb-12 4:06am    
Here i m not passing value to row identity column. if one user insertings means no problem when N number of user inserting means that time alone problem with this trigger

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900