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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Constraints in SQL

Author  Topic 

poptart007
Starting Member

1 Post

Posted - 2003-04-29 : 10:34:20
Just wondering if anyone knows how to implement a constraint to ensure that a yes/no choice is only available to the user.
Thanks

Edited by - merkin on 04/29/2003 10:38:30

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-04-29 : 10:50:26
use a bit field.

or

on a character field use trigger to check at the time of insertion if it's yes/no


or

CREATE TABLE test
(
test_id int PRIMARY KEY,
answer char(3),
CONSTRAINT answer CHECK (answer IN ('yes','no')
)



Edited by - ValterBorges on 04/29/2003 10:52:39
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-04-29 : 12:19:16
quote:

on a character field use trigger to check at the time of insertion if it's yes/no



Are CHECK constraints considered triggers? I assume they have less overhead than a regular triggers?


- Jeff
Go to Top of Page

ValterBorges
Master Smack Fu Yak Hacker

1429 Posts

Posted - 2003-04-29 : 12:50:42
FROM BOL
quote:

Constraints allow you to define the way Microsoft® SQL Server™ 2000 automatically enforces the integrity of a database. Constraints define rules regarding the values allowed in columns and are the standard mechanism for enforcing integrity. Using constraints is preferred to using triggers, rules, and defaults. The query optimizer also uses constraint definitions to build high-performance query execution plans.



Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-04-29 : 13:25:57
oops. didn't see the 'OR' between the comment about using a trigger and then the check constraint. I thought you were implying the CHECK constraint is a trigger.

Never mind!


- Jeff
Go to Top of Page
   

- Advertisement -