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 |
|
amitbarkai
Starting Member
19 Posts |
Posted - 2010-05-27 : 05:07:13
|
| Hey Alli am tring to figure out few things about triggerslet say i want to validate my data before inserting in to my tablefor that we have the instead of insertwhat i could find is a good example thatvalidate a single filed on insert of combination of 2 field can anyone give my an example that prevent the insert if a field equals to valuethanks |
|
|
asgast
Posting Yak Master
149 Posts |
Posted - 2010-05-27 : 06:36:49
|
| if you want to just validate data before inserting, try using check constraint for examples on triggers try looking into BOL http://msdn.microsoft.com/en-us/library/ms189799%28SQL.90%29.aspx |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2010-05-27 : 09:49:03
|
| Validate Data can be done in AFTER trigger (it can rollback the changed data) and AFTER triggers are a WHOLE PILE easier to write & maintain.But I see Triggers as being a long stop. Better to have caught the validation issues before then, if possible, so you can present user-friendly messages / options to the user. A trigger is going to raise an error that will abort the transaction - and is not likely to be handled very gracefully by your application.OTOH a Stored Procedure, or some "middle-tier", could return an error code, and a suitable user-friendly message, which the application could easily use to guide the User |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2010-05-27 : 09:49:27
|
You could also have the business layer of your application validate any data passed to your data layer. http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|