Cannot insert duplicate key row in object 'dbo.TitleClient' with unique index 'XAK1TitleClient'
Ever since I cleaned the data on the SQL Database I've been getting this issue, whereas on the unclean database the issue does not happen. When I run my stored procedure (huge procedure) it returns:
General SQL error. Cannot insert duplicate key row in object 'dbo.TitleClient' with unique index 'XAK1TitleClient'. Cannot insert the value NULL into column 'id_title', table 'Database.dbo.TitleCom'; column does not allow null, insert fails.
Is it possible that I deleted data from开发者_运维知识库 a table that causes this? Or is that impossible?
Does dbo.TitleClient
have an identity column? You might need to run
DBCC CHECKIDENT('dbo.TitleClient')
I'm guessing that the first message
Cannot insert duplicate key row in object 'dbo.TitleClient' with unique index 'XAK1TitleClient'
is because the seed value is out of synch with the existing table values and the second error message
Cannot insert the value NULL into column 'id_title', table 'Database.dbo.TitleCom' column does not allow null, insert fails.
Comes from a failed attempt at inserting the result of scope_identity
from the first statement.
How cleanly did you "clean" the data?
- If some tables still have data, that might be causing a problem.
- Especially if you have triggers resulting in further inserts.
For you to investigate further.
- Take the body of your stored proc, and run it bit-by-bit.
- Eventually, you'll get to the actual statement producing the error.
- Of course if you aren't inserting into
dbo.TitleClient
at this point, then it's certainly a trigger causing problems. - Either way: Now you can easily check the data inserted earlier in your proc to figure out the root cause.
精彩评论