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
 General SQL Server Forums
 New to SQL Server Programming
 Check Constraint

Author  Topic 

sun89
Starting Member

3 Posts

Posted - 2009-09-08 : 14:28:45
in my table , in the "class" attribute i want strings inserted to be either 'gold' or 'silver' ... how can i put that in check constraint? ... plz help!!!

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-09-08 : 15:03:33
You need to have a CHECK contraint on that column...

something like
CHECK (class IN ('gold', 'silver'))

check BOL for further examples.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-08 : 15:05:57
CREATE TABLE myTable(class varchar(6) NOT NULL CHECK (class IN('gold','silver')))

or

ALTER TABLE myTable ADD CONSTRAINT chk_class CHECK (class IN('gold','silver'))
Go to Top of Page

sun89
Starting Member

3 Posts

Posted - 2009-09-08 : 15:16:20
Thanks a lot :)
Go to Top of Page
   

- Advertisement -