Skip to content
Advertisement

SQL Server : Stored Procedure for Preventing Duplicated Values

I have this code which I have created which I want to stop any duplicated values from being inserted into the database, however the values still continue to be able to get into the IF_Translations table. I have tried changing the 0 to a -1 on this line:

Any help?

Code:

Advertisement

Answer

The correct solution is to let the database check the integrity. You would do this with a unique constraint or index (the two are equivalent for this purpose):

You should also fix the ID so it is an IDENTITY column — incrementing the value in your code is not safe, unless you lock the entire table and that is quite expensive.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement