Showing posts with label surprised. Show all posts
Showing posts with label surprised. Show all posts

Monday, March 19, 2012

Composite key cannot allow bit column

Made an interesting discovery today - a column of data type Bit is not allowed to participate in composite key. Rather surprised.

I have a certain unique code that exhibits 2 unique states, which rendered the use of the boolean column, so the uniqueness goes <code>-1 and <code>-0. Is there any 'hack' so to speak to avoid using a Tinyint for the boolean column instead?Perhaps instead you could use a unique constraint composed of the 2 columns.

Terri|||I'm sure its not a good idea to use a field with so few values as a part of key. I think the tree tranversal will be impacted and your performance will suffer.|||Well, SQL Server won't allow me to use it as a key, so no "worries" on that. I will try Terri's unique constraint suggestion later.|||Unique constraints don't allow bit columns to participate either. Sigh.|||Actually, I'm sorry, what I meant was a unique index! I had tried that out before posting and it did not give me an error.

Terri