Intellipaat Back

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

I am not very familiar with databases and the theories behind how they work. Is it any slower from a performance standpoint (inserting/updating/querying) to use Strings for Primary Keys than integers?

1 Answer

0 votes
by (40.7k points)

Yes, from a performance standpoint (i.e. inserting or querying or updating) using Strings for primary keys are slower than integers. But if it makes sense to use string for the primary key then you should probably use it. 

This all will depend on the size of the table you're making it for and the length of the string that is going to be the primary key (i.e. longer strings == harder to compare). 

One shouldn't necessarily use a string for a table that has millions of rows, but the amount of performance slowdown you'll be getting by using the string on smaller tables will be higher than by having an integer which doesn't mean anything in relation to the data.

Related questions

0 votes
1 answer
0 votes
1 answer
asked Dec 12, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Jul 22, 2019 in SQL by Tech4ever (20.3k points)
0 votes
1 answer
asked Dec 9, 2020 in SQL by Appu (6.1k points)

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...