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 Question

Author  Topic 

Going_craazy
Starting Member

9 Posts

Posted - 2008-06-27 : 14:53:22
Hi,

I am trying to add a check constraint to the column "State" to ensure that the state is CA, UT, AZ, WY, OR, or WA. Table name is customer. I tried State LIKE ('CA', 'UT', 'AR', 'WY','WA')

I am getting an error

"- Unable to add constraint 'ValidState'.
Incorrect syntax near ','.

I tried State LIKE ('CA', 'UT', 'AR', 'WY','WA')

Can anybody help me.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-06-27 : 14:59:55
You can't use LIKE for multiple values. Use IN instead.

State IN (...)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Going_craazy
Starting Member

9 Posts

Posted - 2008-06-27 : 15:03:13
Hi,

Thank you for the reply.

Can you tell me any online source for syntax for building expressions in SQL.
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-06-27 : 15:07:11
SQL Server 2000 Books Online
http://msdn2.microsoft.com/en-us/library/aa257103(SQL.80).aspx

SQL Server 2005 Books Online
http://msdn2.microsoft.com/en-us/library/ms130214.aspx

Learning SQL:
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp




CODO ERGO SUM
Go to Top of Page

Going_craazy
Starting Member

9 Posts

Posted - 2008-06-27 : 15:11:28
Thank you.
Go to Top of Page
   

- Advertisement -