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
 Case-insensitive unique constraint?

Author  Topic 

WBuik
Starting Member

2 Posts

Posted - 2007-05-19 : 23:03:09
I have a table in MSSQL 2005 Express that stores user data. I would like to maintain the cases of user names, but I need to insure that they are not duplicated using different cases. Is there a way that I can create a constraint to enforce this?

Thanks,
WBuik

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-05-20 : 00:45:43
Yes if the column has case-insensitive collation.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-20 : 09:25:02
if the column is case insenstive then a simlpe check like

where yourColumn = 'yourUserNameHere'

will suffice.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-05-20 : 16:52:32
[code]
CREATE TABLE MyTable
(
...
MyUserName varchar(1234) COLLATE xxxx
...
)
[/code]
choose appropriate collation "xxxx" for your desired character set, make sure you choose a Case Sensitive (and whether you want Accent Sensitive, or not), then put a Unique Index on that column.

Kristen
Go to Top of Page

WBuik
Starting Member

2 Posts

Posted - 2007-05-31 : 16:53:55
Thanks, this worked great.
Go to Top of Page
   

- Advertisement -