Cities and States (a few data): single table or splitted?












1















I am designing a DB schema and I need to store cities and states. I expect only a few rows, let's say, 20 cities. Example:




id | city | state
1 | Rio de Janeiro | RJ
2 | Niteroi | RJ
3 | Cabo Frio | RJ
4 | Nova Friburgo | RJ
5 | Campos | RJ
6 | São Paulo | SP
7 | Santos | SP
8 | Santo André | SP


As I said, less than 20 cities and only 2 or 3 states ( CHAR(2) ). Regarding performance, which is the best: A single table like the above example, or 2 tables with relationship between both?



PS: I'm not expecting any SELECT ... WHERE 'state'... I'll only select by city and then display which state it belongs to.



Thanks










share|improve this question
















bumped to the homepage by Community 27 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    It depends entirely on what you do with them. But in any event, you should not be doing DB design worrying about performance at this step. You design the DB first, according to the data relations. Do this right and the performance will take care of itself 90% of the time. Only later when you know if you have a performance problem, should you start worrying about it.

    – RBarryYoung
    Jan 6 '16 at 0:35











  • When the table contains very few rows and does not change frequently you can denormalize it and use single table instead of two. You can add a new data field geo_level to choose between the state level or city level, if you need it in future.

    – rathishDBA
    Jan 6 '16 at 6:27
















1















I am designing a DB schema and I need to store cities and states. I expect only a few rows, let's say, 20 cities. Example:




id | city | state
1 | Rio de Janeiro | RJ
2 | Niteroi | RJ
3 | Cabo Frio | RJ
4 | Nova Friburgo | RJ
5 | Campos | RJ
6 | São Paulo | SP
7 | Santos | SP
8 | Santo André | SP


As I said, less than 20 cities and only 2 or 3 states ( CHAR(2) ). Regarding performance, which is the best: A single table like the above example, or 2 tables with relationship between both?



PS: I'm not expecting any SELECT ... WHERE 'state'... I'll only select by city and then display which state it belongs to.



Thanks










share|improve this question
















bumped to the homepage by Community 27 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 1





    It depends entirely on what you do with them. But in any event, you should not be doing DB design worrying about performance at this step. You design the DB first, according to the data relations. Do this right and the performance will take care of itself 90% of the time. Only later when you know if you have a performance problem, should you start worrying about it.

    – RBarryYoung
    Jan 6 '16 at 0:35











  • When the table contains very few rows and does not change frequently you can denormalize it and use single table instead of two. You can add a new data field geo_level to choose between the state level or city level, if you need it in future.

    – rathishDBA
    Jan 6 '16 at 6:27














1












1








1








I am designing a DB schema and I need to store cities and states. I expect only a few rows, let's say, 20 cities. Example:




id | city | state
1 | Rio de Janeiro | RJ
2 | Niteroi | RJ
3 | Cabo Frio | RJ
4 | Nova Friburgo | RJ
5 | Campos | RJ
6 | São Paulo | SP
7 | Santos | SP
8 | Santo André | SP


As I said, less than 20 cities and only 2 or 3 states ( CHAR(2) ). Regarding performance, which is the best: A single table like the above example, or 2 tables with relationship between both?



PS: I'm not expecting any SELECT ... WHERE 'state'... I'll only select by city and then display which state it belongs to.



Thanks










share|improve this question
















I am designing a DB schema and I need to store cities and states. I expect only a few rows, let's say, 20 cities. Example:




id | city | state
1 | Rio de Janeiro | RJ
2 | Niteroi | RJ
3 | Cabo Frio | RJ
4 | Nova Friburgo | RJ
5 | Campos | RJ
6 | São Paulo | SP
7 | Santos | SP
8 | Santo André | SP


As I said, less than 20 cities and only 2 or 3 states ( CHAR(2) ). Regarding performance, which is the best: A single table like the above example, or 2 tables with relationship between both?



PS: I'm not expecting any SELECT ... WHERE 'state'... I'll only select by city and then display which state it belongs to.



Thanks







mysql select foreign-key primary-key






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 6 '16 at 2:24









miracle173

6,5671838




6,5671838










asked Jan 6 '16 at 0:27









gugabguerragugabguerra

1112




1112





bumped to the homepage by Community 27 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 27 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 1





    It depends entirely on what you do with them. But in any event, you should not be doing DB design worrying about performance at this step. You design the DB first, according to the data relations. Do this right and the performance will take care of itself 90% of the time. Only later when you know if you have a performance problem, should you start worrying about it.

    – RBarryYoung
    Jan 6 '16 at 0:35











  • When the table contains very few rows and does not change frequently you can denormalize it and use single table instead of two. You can add a new data field geo_level to choose between the state level or city level, if you need it in future.

    – rathishDBA
    Jan 6 '16 at 6:27














  • 1





    It depends entirely on what you do with them. But in any event, you should not be doing DB design worrying about performance at this step. You design the DB first, according to the data relations. Do this right and the performance will take care of itself 90% of the time. Only later when you know if you have a performance problem, should you start worrying about it.

    – RBarryYoung
    Jan 6 '16 at 0:35











  • When the table contains very few rows and does not change frequently you can denormalize it and use single table instead of two. You can add a new data field geo_level to choose between the state level or city level, if you need it in future.

    – rathishDBA
    Jan 6 '16 at 6:27








1




1





It depends entirely on what you do with them. But in any event, you should not be doing DB design worrying about performance at this step. You design the DB first, according to the data relations. Do this right and the performance will take care of itself 90% of the time. Only later when you know if you have a performance problem, should you start worrying about it.

– RBarryYoung
Jan 6 '16 at 0:35





It depends entirely on what you do with them. But in any event, you should not be doing DB design worrying about performance at this step. You design the DB first, according to the data relations. Do this right and the performance will take care of itself 90% of the time. Only later when you know if you have a performance problem, should you start worrying about it.

– RBarryYoung
Jan 6 '16 at 0:35













When the table contains very few rows and does not change frequently you can denormalize it and use single table instead of two. You can add a new data field geo_level to choose between the state level or city level, if you need it in future.

– rathishDBA
Jan 6 '16 at 6:27





When the table contains very few rows and does not change frequently you can denormalize it and use single table instead of two. You can add a new data field geo_level to choose between the state level or city level, if you need it in future.

– rathishDBA
Jan 6 '16 at 6:27










1 Answer
1






active

oldest

votes


















0














CHAR(2) CHARACTER SET latin1 takes only 2 bytes. You are not going to improve significantly on that by using an id TINYINT UNSIGNED (1 byte) to 'normalize' it.



Splitting into 2 tables is something I call "over-normalizing".



JOINs are pretty cheap, but they are not free. This is a disadvantage of the 2-table approach.



While you are asking this question, I suggest you implement it both ways, see how big the tables are, see how fast the queries are, etc. Use it as a learning exercise.



Yes, there will be other cases where 2 tables is better.






share|improve this answer



















  • 1





    Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

    – gugabguerra
    Jan 6 '16 at 1:14








  • 1





    :) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

    – Rick James
    Jan 6 '16 at 3:57











  • Good point! I'll check it out.

    – gugabguerra
    Jan 6 '16 at 5:45











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f125319%2fcities-and-states-a-few-data-single-table-or-splitted%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














CHAR(2) CHARACTER SET latin1 takes only 2 bytes. You are not going to improve significantly on that by using an id TINYINT UNSIGNED (1 byte) to 'normalize' it.



Splitting into 2 tables is something I call "over-normalizing".



JOINs are pretty cheap, but they are not free. This is a disadvantage of the 2-table approach.



While you are asking this question, I suggest you implement it both ways, see how big the tables are, see how fast the queries are, etc. Use it as a learning exercise.



Yes, there will be other cases where 2 tables is better.






share|improve this answer



















  • 1





    Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

    – gugabguerra
    Jan 6 '16 at 1:14








  • 1





    :) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

    – Rick James
    Jan 6 '16 at 3:57











  • Good point! I'll check it out.

    – gugabguerra
    Jan 6 '16 at 5:45
















0














CHAR(2) CHARACTER SET latin1 takes only 2 bytes. You are not going to improve significantly on that by using an id TINYINT UNSIGNED (1 byte) to 'normalize' it.



Splitting into 2 tables is something I call "over-normalizing".



JOINs are pretty cheap, but they are not free. This is a disadvantage of the 2-table approach.



While you are asking this question, I suggest you implement it both ways, see how big the tables are, see how fast the queries are, etc. Use it as a learning exercise.



Yes, there will be other cases where 2 tables is better.






share|improve this answer



















  • 1





    Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

    – gugabguerra
    Jan 6 '16 at 1:14








  • 1





    :) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

    – Rick James
    Jan 6 '16 at 3:57











  • Good point! I'll check it out.

    – gugabguerra
    Jan 6 '16 at 5:45














0












0








0







CHAR(2) CHARACTER SET latin1 takes only 2 bytes. You are not going to improve significantly on that by using an id TINYINT UNSIGNED (1 byte) to 'normalize' it.



Splitting into 2 tables is something I call "over-normalizing".



JOINs are pretty cheap, but they are not free. This is a disadvantage of the 2-table approach.



While you are asking this question, I suggest you implement it both ways, see how big the tables are, see how fast the queries are, etc. Use it as a learning exercise.



Yes, there will be other cases where 2 tables is better.






share|improve this answer













CHAR(2) CHARACTER SET latin1 takes only 2 bytes. You are not going to improve significantly on that by using an id TINYINT UNSIGNED (1 byte) to 'normalize' it.



Splitting into 2 tables is something I call "over-normalizing".



JOINs are pretty cheap, but they are not free. This is a disadvantage of the 2-table approach.



While you are asking this question, I suggest you implement it both ways, see how big the tables are, see how fast the queries are, etc. Use it as a learning exercise.



Yes, there will be other cases where 2 tables is better.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 6 '16 at 0:48









Rick JamesRick James

43.6k22259




43.6k22259








  • 1





    Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

    – gugabguerra
    Jan 6 '16 at 1:14








  • 1





    :) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

    – Rick James
    Jan 6 '16 at 3:57











  • Good point! I'll check it out.

    – gugabguerra
    Jan 6 '16 at 5:45














  • 1





    Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

    – gugabguerra
    Jan 6 '16 at 1:14








  • 1





    :) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

    – Rick James
    Jan 6 '16 at 3:57











  • Good point! I'll check it out.

    – gugabguerra
    Jan 6 '16 at 5:45








1




1





Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

– gugabguerra
Jan 6 '16 at 1:14







Thanks! I agree with you in all aspects. 2 tables will demand more work to the programmer and brings no practical improvement for the DB. Over-normalizing was perfect (lol) ! I have pretty much the same information but in the oposite situation in another software: lots of select statements by 'state' column to find state's full name, some other information and cities belonging to it... so in this case 2 table is better. Then I'll also take your suggestion and implement both ways as a learning exercise. Thanks!!

– gugabguerra
Jan 6 '16 at 1:14






1




1





:) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

– Rick James
Jan 6 '16 at 3:57





:) Even in the case of a separate table for States, I would argue for the key to be RJ, SP, etc, not 1, 2, etc.

– Rick James
Jan 6 '16 at 3:57













Good point! I'll check it out.

– gugabguerra
Jan 6 '16 at 5:45





Good point! I'll check it out.

– gugabguerra
Jan 6 '16 at 5:45


















draft saved

draft discarded




















































Thanks for contributing an answer to Database Administrators Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f125319%2fcities-and-states-a-few-data-single-table-or-splitted%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liste der Baudenkmale in Friedland (Mecklenburg)

Single-Malt-Whisky

Czorneboh