Wednesday, March 21, 2012

Front-end input error checking or backend...?

This maybe belongs in the Data-Access Forum, but I'm not sure.

Is it generally a better idea to enforce things like unique constraints in the Database or the Webform? Say for example I want to make sure no duplicate Social Security Numbers are entered. Is it better to have an "If Exists" clause in my query, with a function to deal with it in the application or is it better to just fire the data to SQL Server and let the unique constraint on the dbase column deal with it? I then still have to have some code in my application to deal with the potential exisatance of that number, so is it a case of tomatoe, tomahtoe? If I understand things correctly, SQL server will return an error code if the piece of data does exist, and I will be able to parse the error code and display a message to the user.

Are there performance/coding issues involved? Best practices?In ASP.NET use Validator controls and to disallow duplicates make your table UNIQUE INDEX compatible because SQL Server will not allow the creation of UNIQUE INDEX on Columns that already include duplicate values. Include IGNORE_DUP_KEY in your create INDEX statement. Which means you are using both the application and the database. Hope this helps.

Kind regards,
Gift Peddie

No comments:

Post a Comment