jlewis (jlewis@discussions.microsoft.com) writes:
[quoted text, click to view] > Below is a query I'm working on. I want to force the Gender column to be
> UPPERCASE but can't figure out how to do it. Any help is GREATLY
> appreciated!!
> ---------------------------------------------------------
>
> CREATE TABLE Person
> (PersonID INT CONSTRAINT ROWpk_person PRIMARY KEY,
> LastName NVARCHAR(50) CONSTRAINT ROWnn_person_lname NOT NULL,
> FirstName NVARCHAR(50) CONSTRAINT ROWnn_person_fname NOT NULL,
> Gender NVARCHAR(50) DEFAULT 'F' CONSTRAINT ROWck_person_gender
> CHECK ((Gender='F') or (Gender='M')),
> Weight INT CONSTRAINT ROWck_person_weight
> CHECK ((Weight>84) AND (Weight<251)),
> DateOfBirth DATETIME,
> );
First, Gender should be char(1), not nvarchar(50), since you are only
permitting two values, and none of them are Unicode values.
Here is a way to write the constraint:
CHECK (Gender COLLATE Finnosh_Swedish_BIN IN ('F', 'M'))
by forcing a binary collation in the check, you make the test
case-sensitive. You can pick any collation you like as long as its
binary or case-sensitive.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at