[dba-SQLServer] Enforcing a rule

Alan Lawhon lawhonac at hiwaay.net
Mon Aug 29 02:22:21 CDT 2011


John:

I'm not sure exactly how triggers would apply to your specific situation,
(i.e. exactly how you would go about coding a solution to your problem), but
Francisco may be on to something.  In "Section 4 - Advanced SQL skills" on
pages 470 and 471 of "murach's SQL Server 2008 for developers" book, the
author has a section entitled "How to use triggers to enforce data
consistency".  The problem (and solution) he presents may not be precisely
applicable to the problem you're describing, but you may be able to get a
good idea of how to go about solving your problem from reading those pages.

I'm in the early stages of trying to figure out and "learn" SQL Server.
>From what I've read so far, triggers seem to be designed to ensure data
validation (data consistency) and maintain relationships between tables.
What you're trying to do seems related to this, so maybe a stored procedure
that includes a trigger will solve your problem.

This is great - I'm now a SQL Server consultant!   :-)))

Alan C. Lawhon

-----Original Message-----
From: dba-sqlserver-bounces at databaseadvisors.com
[mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of Francisco
Tapia
Sent: Sunday, August 28, 2011 8:49 PM
To: Discussion concerning MS SQL Server
Subject: Re: [dba-SQLServer] Enforcing a rule

Have you looked into update triggers on tables?

Sent from my mobile

On Aug 28, 2011, at 6:47 PM, jwcolby <jwcolby at colbyconsulting.com> wrote:

> I can certainly do that but I am hoping to learn how to use the SQL Server
engine to do these things.
>
> John W. Colby
> www.ColbyConsulting.com
>
> On 8/28/2011 7:52 PM, Rocky Smolin wrote:
>> I would use the Before Update event of the form to verify that at last
>> choice was made.
>>
>> Rocky
>>
>>
>> -----Original Message-----
>> From: dba-sqlserver-bounces at databaseadvisors.com
>> [mailto:dba-sqlserver-bounces at databaseadvisors.com] On Behalf Of jwcolby
>> Sent: August 28, 2011 3:41 PM
>> To: Sqlserver-Dba
>> Subject: [dba-SQLServer] Enforcing a rule
>>
>> I have a table where the client is either a parent type (from a list of
>> parent types) or a professional type (from a list of professional types).
I
>> need to enforce that at least one of the fields is filled.  IOW both
cannot
>> be null, but either one can be null or both can be filled.
>>
>> How do I do something like that?  I have never used database level
>> constraints other than pk/fk so I do not know how to set something like
this
>> up.  Any detailed instructions or a pointer to a web page would be
>> appreciated.
>>
>> Thanks,
>>
>> --
>> John W. Colby
>> www.ColbyConsulting.com
>> _______________________________________________
>> dba-SQLServer mailing list
>> dba-SQLServer at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
>> http://www.databaseadvisors.com
>>
>>
>> _______________________________________________
>> dba-SQLServer mailing list
>> dba-SQLServer at databaseadvisors.com
>> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
>> http://www.databaseadvisors.com
>>
>>
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
>
_______________________________________________
dba-SQLServer mailing list
dba-SQLServer at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
http://www.databaseadvisors.com




More information about the dba-SQLServer mailing list