Im working in an odd problem and I need help to figure this out.
I have a database in which there is an identifier column (defined as int is not null, Identity, starts at 1, increments by 1) in addition to all the application data columns. The primary key for the table is the column identifier, other components.
There is no data set that I can use as a "natural primary key", because the application must allow multiple representations of the same data.
I have a stored procedure, which is the only way to add new records to the table (except for logging into the server directly as the owner of db)
While QA tested the application this morning, they entered a new record into the database (using the application, as expected, and as they did over the past two weeks), and encountered a primary key violation on this table.
This is the same thing that I have been doing Primary Keys for about 10 years and have never come across this.
Any ideas on how to fix this? Or is it one of those cosmic ray failures that appears once over time.
Thanks for any advice you can give.
Nigel
Edited at 1:15 pm ET on June 12 to provide additional information.
A simplified version of the circuit ...
CREATE TABLE [dbo].[tbl_Queries]( [QueryID] [int] IDENTITY(1,1) NOT NULL, [FirstName] [varchar](50) NOT NULL, [LastName] [varchar](50) NOT NULL, [Address] [varchar](150) NOT NULL, [Apt#] [varchar](10) NOT NULL ... <12 other columns deleted for brevity> [VersionCode] [timestamp] NOT NULL, CONSTRAINT [PK_tbl_Queries] PRIMARY KEY CLUSTERED ( [QueryID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
(also removed the default instructions)
The stored procedure is as follows
insert into dbo.tbl_Queries ( FirstName, LastName, [Address], [Apt#]...) values ( @firstName, @lastName, @address, isnull(@apt, ''), ... )
It does not even look at the identifier column, does not use IDENTITY, @@ scope_identity or something like that, it is just a file and is forgotten.
I am as sure as I can be that the identifier value was not reset, and that no one is using direct database access to enter values. The only time in this project that uses identifier insertion is the initial deployment of the database to set specific values ββin the lookup tables.
The QA team again tried immediately after receiving the error and was able to send the request successfully, and since then they have tried to reproduce it and still have not succeeded.
I really appreciate people's ideas.