Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I'm in the process of creating a table and it made me wonder.

If I store, say cars that have a make (fx BMW, Audi ect.), will it make any difference on the query speed if I store the make as an int or varchar?

So is

SELECT * FROM table WHERE make = 5 AND ...;

Faster/slower than

SELECT * FROM table WHERE make = 'audi' AND ...;

or will the speed be more or less the same?

1 Answer

0 votes
by (40.4k points)

Int comparisons are faster than varchar comparisons, and ints take much less space than varchars.

This is applicable true for both unindexed and indexed access. You can use an indexed int column to make it faster.

If you are interested in the space usage of different data types:

int fields always occupy between 2 and 8 bytes, with 4 being usually more than enough ( -2147483648 to +2147483647 )

character types occupy 4 bytes plus the actual strings.

Related questions

0 votes
1 answer
asked Jul 4, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
1 answer
asked Dec 17, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.7k users

Browse Categories