Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Creating a Check Constraint Expand / Collapse
Author
Message
Posted Tuesday, April 08, 2008 6:17 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 20, 2012 12:18 AM
Points: 4, Visits: 12
Hello. I am obviously very new to SQL Server 2005 Express. I am an Access developer and I am giving a try to SQL Server Express. Maybe my question will be answered faster this way 8)

I am going through a book (... In 24 Hours series) and every time I try to complete a simple exercise about creating a (seems like a) Check Constraint I get an error. Here's what I am doing:

The field is State: Char (2) and we want to apply the constraint where only the following values are accepted: CA, UT, AZ WY, and a few others.

My steps:
I click the selected to the left of the State field and click Manage Check Constraints.
In the Check Constraint dialog I click Add and the constraint CK_Table_1* appears. The name is simply CK_Table_1.
I name the constraint ckState (like in the book)
In the Expression I type @State In('CA', 'UT', 'AZ', 'WY') and as soon as I hit Enter a message appears that there is an error in the constraint and ask me if I want to Edit it.

I am at loss here because this matches the screen shot in the book.

Can anyone help?

I hope I provided enough information.
Post #481464
Posted Tuesday, April 08, 2008 6:50 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 10, 2010 5:07 AM
Points: 2,732, Visits: 23,078
Remove the @ symbol

State In('CA', 'UT', 'AZ', 'WY')

"State" is referring to your field name.
Post #481487
Posted Tuesday, April 08, 2008 6:59 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 20, 2012 12:18 AM
Points: 4, Visits: 12
Thank you so much Michael,

The book does specify the @ but it is incorrect! Thank you again. I will remember.

Daniel
Post #481494
Posted Tuesday, April 08, 2008 7:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, December 16, 2008 5:37 AM
Points: 2, Visits: 235
Remove @ from your statement( @State In('CA', 'UT', 'AZ', 'WY'))
Post #481498
Posted Tuesday, April 08, 2008 7:03 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 10, 2010 5:07 AM
Points: 2,732, Visits: 23,078
don't believe everything you read.
Post #481499
Posted Sunday, June 27, 2010 8:15 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, August 15, 2010 10:22 PM
Points: 8, Visits: 22
hello, I'm a beginner in SQL Server 2005, i'm trying to create check constraint, and when i'm trying to create it, an error message was appear.
my steps are:
1) The field is ZIP using nchar(5),
2) in the Expression I type: zip LIKE '[0-9][0-9][0-9][0-9][0-9]'
3) When I click Save button, there was an error message and unable to save the changes

kindly help...
Post #943607
Posted Sunday, June 27, 2010 11:36 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 6:47 AM
Points: 41,549, Visits: 34,471
Please post new questions in a new thread. Thanks.


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #943649
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse