Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rules

Status
Not open for further replies.

dgillz

Instructor
Mar 2, 2001
10,036
1
38
US
In MS SQL Server enterprize manager, I see where you can set up "rules". Does anyone have and idea how to do this? What I would like to do is set up a rule so that the value of a certain field in a table cannot be zero.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Not so sure what rules are either - never looked at them

You could always implement a check constraint

i.e. <field> <> 0

Set this up through enterprise manager when you design the table by clicking on the check constraints tab (via properties) and inputting the above text for the relevant field as a new constraint

Hope this helps

Damian
 
I am not huge fan of the rules in SQL Server because it is another location (and often forgetten area) that needs to be considered in future changes and updates.

As long as you set a default value and then implement a trigger that sets the field to a default value if it is equal to zero, then you should be fine.

The real question, is why not zero. Is it a totalling field that you plan to divide by? Etc. Often, when a field is not to be zero, there is a larger issue at hand and rules, default values and triggers may not handle this other than to create their own unique problems.

Usually, the best process is to have code to handle zero values.

Ken
 
Collierd,

Where would I enter the check constraint you mentioned?

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
Right click the table required and design
right click the field required and check constraints
Input ([ <fieldname> ]) <> 0 under the Constraint expression header
Close and save

Damian

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top