Country List for SQL Server 2008!

by Mikael Henriksson 14. November 2008 16:00

Hi, today I had to do an extremely boring task! I had to create a table for holding the worlds countries. Not only had I to create the stupid table I had to fill it with all the worlds countries. Thanks to the guys over at http://snippets.dzone.com/. They had a post with all the countries of the world stored as a html <select>. This was not an option for me (tihihi) I needed to store it in a sql server database. What I did was to convert the select with options to:

<asp:DropDownList ID="DropDownListCountry" runat="server">
    <asp:ListItem Value="0" Selected="true">Select Country</asp:ListItem>


Now I could easily iterate through all the Items and create a massive Insert statement with the help of a stringbuilder. I am not going to go into the details I am just going to share with you all the results of the work. I do not want to do this myself again so I suppose none of you want to either. All you need to do is copy+paste, I omitted line numbers so you don’t have to manually remove those.

EDIT 2009-03-24:
Obviously since switching blogs the actual file has vanished. I’ll try to post a new file! :) I added country codes for 174 countries but there is still 80 something missing.

CountriesIncludingInserts.sql (66,09 kb)

Tags:

SQL Server