Alex Rivera | Logout

SQL: What is better a Bit or a char(1)

Asked 2011-02-24T14:46:07.450
12

Is there any performance difference on retrieving a bit or a char(1) ?

Just for curiosity =]

UPDATE: Suposing i'm using SQL Server 2008!

Edit
Report

1 Answer

3

a bit and a char(1) will both take a 1 byte to store,assuming you only have 1 bit column in the table, SQL Server will store up tp 8 bit columns in 1 byte. I don't think there is a difference in performance.

One thing to be aware of is that you can't do sum on a bit column

CREATE TABLE #test( a BIT)

INSERT #test VALUES (1)
INSERT #test VALUES (1)

SELECT sum(a) FROM #test

Msg 8117, Level 16, State 1, Line 1
Operand data type bit is invalid for sum operator.

you have to convert it first

SELECT sum(CONVERT(INT,a)) FROM #test
answered 2011-02-24T15:16:11.210

Your Answer