Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
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.7k 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
2 answers
0 votes
2 answers
asked Oct 7, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
0 votes
2 answers

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...