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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 best practice

Author  Topic 

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2003-07-11 : 20:18:40

I have a few columns in my database that either just store a 0 or a 1 basically to denote if something is yes/no , true/false, checked / unchecked. I store this column as a tinyint.

Would it be better to store it as a char, and have Y/N or T/F etc?

Any performance benefits of doing it either way?

just wondering..

Thanks alot
Mike123

SamC
White Water Yakist

3467 Posts

Posted - 2003-07-11 : 20:42:10
With all due respect, I think the answer is "whatever".

When you query a 2 value column it's possible to return whatever you want in SQL anyhow using a CASE statement.

Select CASE WHEN MyCol=1 THEN 'T' ELSE 'F' END as MyCol

Or, you could add a calculated column to the table that does the same thing. Or have multiple calculated columns some which say Y/N, T/F, 1/0.

I suggest you store it in whatever format makes your query's perform best.

Sam

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-07-12 : 15:34:00
Or would it be better to have another table and just store the primary keys where the value is true (or false).
Depends how you want to use it.

This will make it efficient for retrieving those records (especially if there are few of them) but may make things more complicated.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

MichaelP
Jedi Yak

2489 Posts

Posted - 2003-07-13 : 03:22:49
For such things, I use a BIT field. I think it's smaller than TinyInt.


Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2003-07-13 : 06:26:53
You think or you know ?

I find that Bit fields can be a bit of a pain to work with in ADO. But if you have a few of them yes they will use up a couple less bytes.

Damian
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-07-13 : 16:59:27
Bytes schmites. I've never seen an app where the difference of 7 bits would make a difference.

Go for the T/F.

Sam

Go to Top of Page

mike123
Master Smack Fu Yak Hacker

1462 Posts

Posted - 2003-07-14 : 02:20:08

its just that its queried alot (400,000 + times a day) and it will be only going up .. and the database server is already under heavy load .. i think i'll just stick with tinyint since I have had no problems so far .. if i could get a 5% improvement i would gladly change it


thanks alot
mike123

Go to Top of Page
   

- Advertisement -