I have a program running on SQL Server 2008. There is a function to create a new shipment. The minimum data needed to create a shipment is the idno, subno and class. The Primary Key is idno + idsub. I created a stored procedure to create a new shipment as follows
ALTER Proc [dbo].[spDP_CreateNewShipment](@Class char(10),@idno int = 0, @idsub smallint = 1)
as
If @idno = 0
Begin
Select @idno = Max(idno)+1 From Shipment
End
Insert Into Shipment
(idno,idsub, class)
Values (@idno,@idsub,@class)
If I pass it an @idno of 0, it should create a shipment with the next available idno. This works great except sometimes two new shipments will get the same new idno. It would seem that the timing would have to be so exactly the same that this should be close to impossible, yet it happens. The only other possibility I can think of is that the Insert might be getting buffered and might not happen immediately. I know very little about SQL Server settings. Does anyone know of a setting that might cause the write not to happen immediately?