Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

custom error message on check constraint. Expand / Collapse
Author
Message
Posted Saturday, July 18, 2009 11:39 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, November 16, 2009 1:34 PM
Points: 35, Visits: 55
Hi, I'm just wonder what is the best way or is it even possible to have a customer error message for a simple check constraint such as.

ALTER TABLE tblJobsCL
ADD CONSTRAINT CK_PlannedEndDate_2
CHECK (PlannedEndDate >= PlannedStartDate)

All the error message handling can I find in my books or online seem to be for triggers.

Thank for your help
Asta
Post #755326
Posted Saturday, July 18, 2009 11:46 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Yesterday @ 12:11 PM
Points: 42,470, Visits: 35,541
You can't put a custom error in a check constraint.

Two options.
1) (recommended)
Use a check constraint, have the front end app handle the error and produce whatever custom error that you want

2) use a trigger.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #755329
Posted Saturday, July 18, 2009 11:50 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, November 16, 2009 1:34 PM
Points: 35, Visits: 55
Thanks, glad I asked, saves me looking for something that does not exist.

Asta
Post #755332
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse