Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rico1931
Starting Member
37 Posts |
Posted - 2009-06-25 : 11:56:55
|
| HelloI was wondering if there was a way to make a custom SQL error. Currently I have a web page that does a INSERT and the primary key is something the User puts in. If there are duplicates of the Primary Key it returns a error of 'Violation of PRIMARY KEY constraint 'PK_ID'. Cannot insert duplicate key in object 'dbo.table' ....This error is fine but I don't want the end user to see it I want a friendly one that says Please go back and insert a new ID number because duplicates are not allowed. To accomplish this do I have to make another webpage before the Insert is done to check first or can I just have SQL do this before Insert is ran?Thanks |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2009-06-25 : 14:12:23
|
| no you check before you insert in the same stored procedure... IF NOT EXISTS (SELECT * FROM YourTable WHERE ....)and return an error message if the record exists. You do this all in same procedure.. no need to create separate pages or separate processes/procedures.Dinakar Nethi************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
|
|
|