August 6, 2020 at 7:34 pm
In table tUSERI primary key was added in the column [Email].
I deleted a user abc@gmail.com from tUSER.
When I try to add the same user abc@gmail.com got the following error.
What causes the error?
Please help clean and update the table tUSER.
Violation of PRIMARY KEY constraint 'PK_tuser_2'. Cannot insert duplicate key in object 'dbo.tuser'. The duplicate key value is (abc@gmail.com)
August 6, 2020 at 9:53 pm
Doesn't look like you deleted the user since abc@gmail.com still exists in the table. The error is what the message is telling you - abc@gmail.com already exists in the table and with that being the primary key, the values for Email need to be unique in the table.
Sue
August 7, 2020 at 12:14 pm
I did not use code to delete it.
I open table in edit mode and then hit delete key to delete it.
Does it make difference?
I checked it many times the record is not in table but still causes error.
August 7, 2020 at 2:05 pm
Run this query, and see what is returned:
SELECT * FROM dbo.tuser WHERE email = 'abc@gmail.com'
If results are returned, then run this:
DELETE dbo.tuser WHERE email = 'abc@gmail.com'
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
August 7, 2020 at 3:34 pm
I did not use code to delete it.
I open table in edit mode and then hit delete key to delete it.
Does it make difference?
I checked it many times the record is not in table but still causes error.
When you open a table in SSMS in edit mode, you lock the entire table. Which is probably not a good thing to do in a production environment.
So, yes, it does make a difference.
Michael L John
If you assassinate a DBA, would you pull a trigger?
To properly post on a forum:
http://www.sqlservercentral.com/articles/61537/
August 7, 2020 at 3:53 pm
I did many times in SQL 2012.
From now on I will do it in code.
Thank you.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy