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 |
|
hrishy
Starting Member
47 Posts |
Posted - 2008-07-22 : 05:00:05
|
| I need to enforce a constarint something like thisNameMasterName Code Phone1 Phone2H1 1 NULL NULLH1 2 300 400H2 1 100 100H3 2 200 800H4 1 NULL NULLNameCountryRefName Code Country H1 1 Ghana H1 2 USA H2 2 USAH3 1 GHANAH4 1 USACountryRefCode Country PhoneMandatory1 Ghana N2 USA Y3 UK YI need to enforce the constraint wheneever a new record is added to the name master table and the country code feild is in USAor UK then since the phone mandatory feild is Y we cannot have phone numbers as nullI know this can be done in the application but should'nt the database also enforce this constraint ?But i am currently clueless how to enforce it at the database level.regardsHrishy |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-22 : 05:07:26
|
You can write a trigger to check of a namemaster record belongs to an USA telephone number and rollback the transaction (generate an error) if the phonenumber is empty or is null. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-22 : 05:08:44
|
| if you want to do this at db level you need to write a trigger on NameMaster to check this and raise error if not followed. |
 |
|
|
|
|
|