Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
What is faster in a SQL Select Char or Integer?
Message
 
 
À
11/08/2011 11:12:04
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01520691
Message ID:
01520697
Vues:
32
>>>>Hi,
>>>>
>>>>I am deciding on what type of field/column/expression to use for extracting records from a table. My choices are:
>>>>1. Char field (of about 10 to 20) (depends on the business rule) that will be empty ('') for certain records
>>>>2. Integer field that will have an entry 1000 (or some large number) for certain records.
>>>>
>>>>So the SQL Select will be approximately as following:
>>>>
>>>>1.
>>>>
>>>>select * from Mytable where <SomeWhereExpression>  and len(rtrim(ltrim(char_field))) > 0
>>>>
>>>>
>>>>2.
>>>>
>>>>select * from Mytable where <SomeWhereExpression>  and integ_field < 1000
>>>>
>>>>
>>>>Generally the size of the MyTable will be about 10,000 to 30,000 (just guess on my part).
>>>>
>>>>Which of the above (given that there is an index in SQL Server on both fields) will execute faster (generally)?
>>>>
>>>>TIA.
>>>
>>>
>>>The first I guess
>>>- integer is only 4 bytes to compare
>>
>>Gregory,
>>
>>I am sorry but your message is not 100% clear (and it is probably just me). You are saying the 1st but then you refer to the second case with the word "only". Could you please clarify? Thank you.
>
>
>
>Sorry, my mistake - see my anser to Nadya

Yes, I saw that. Thank you for clarifying. And as I was reading your's and Naomi's exchange of messages I realized that I could have assigned SmallInt type to this column since I don't foresee values ever being greater than 10,000 and never negative. So the search will be even faster. Tengo razon?
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform