Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to write a program in sqlserver storeprocedure,which will accept only unique value,if the end user insert same value for a column attribute it will raise a error,pls help me
Posted
Comments
amritbdk 10-Aug-13 4:53am    
pls explain with a eg
Maciej Los 10-Aug-13 8:39am    
Not clear. Please, be more specific and provide more details.

1 solution

This is the pseudo code.

First option
1. Check if the value already exist in the table.
2. If yes thorow the error.
3. Else to insert statement.

Second Option
1. Set the unique constraint on the field.
2. put insert statement between try catch block.
3. Catch the constraint violation exception and raise the error.

NOTE: Even in first option you need to set the unique contraint.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900