<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic " Import GeoNames dump into SQL Server"]]></title>
		<link>http://forum.geonames.org/gforum/posts/list/6.page</link>
		<description><![CDATA[Latest messages posted in the topic " Import GeoNames dump into SQL Server"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title> Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ Johannes Beck has written a how to :
http://johanneskebeck.spaces.live.com/Blog/cns!42E1F70205EC8A96!3782.entry

New 15. Jan 2009: load the GeoNames locations into SQL Server Spatial
http://blogs.msdn.com/edkatibah/archive/2009/01/13/loading-geonames-data-into-sql-server-2008-yet-another-way.aspx

There are also some threads in the GeoNames forum : 
http://forum.geonames.org/gforum/posts/list/817.page
http://forum.geonames.org/gforum/posts/list/88.page
http://forum.geonames.org/gforum/posts/list/673.page

Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#3808</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#3808</link>
				<pubDate><![CDATA[Mon, 31 Mar 2008 08:44:01]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ Hi, i am new to geonames dump.

But i would like to import all the city names in the world which has population greater than 15000.


Can you please  help me, how can i use that dump, and how can i import that into our local database.

Waiting for response....

Thanks,
Sateesh. :)  :)]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4629</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4629</link>
				<pubDate><![CDATA[Wed, 10 Sep 2008 06:46:02]]> GMT</pubDate>
				<author><![CDATA[ sateesh]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ I am a little confused if you could please clarify..
 Per John Becks instructions
"Johannes Beck has written a how to :
http://johanneskebeck.spaces.live.com/Blog/cns!42E1F70205EC8A96!3782.entry" 

The above uses the allcountry.txt input file which does not match the geonomes table that he is using.  There is a clear mismatch in the number of fields for example the modified date  is lacking. The geonomes table the he is using should be for a differnet input file. Let me know if you see otherwise ..]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4950</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4950</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 02:18:04]]> GMT</pubDate>
				<author><![CDATA[ bemall]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ The modified date is there called 'moddate'.

Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4954</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4954</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 07:15:00]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ I was just using the modified date as an example. There is a general mismatch. The allcountries.txt input file contains 11 columns while the create genome table contains 19 columns...]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4958</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4958</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 17:07:01]]> GMT</pubDate>
				<author><![CDATA[ bemall]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ Respectfullhy, has anyone verified these links or is the input file newer and simply does not match the old postings ?]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4959</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4959</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 17:07:57]]> GMT</pubDate>
				<author><![CDATA[ bemall]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ Oh, I see you are trying to load the postal code dump into the toponym table. This does not work, but it is a piece of cake to modify and adapt the scripts, isn't it?
There are two dumps, you have to decide which one you want.

Best

Marc]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4961</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4961</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 19:02:52]]> GMT</pubDate>
				<author><![CDATA[ marc]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ No I am not doing anything with postal codes. I am simply trying to load allCountries.txt.

None of the links or explanations seem to work due to the difference in number of columns]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4962</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4962</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 19:34:52]]> GMT</pubDate>
				<author><![CDATA[ bemall]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ "I see you are trying to load the postal code dump into the toponym table"

I am not sure what gives you this impression becasue I do mentin that I am trying to load AllCountries.txt and the columns do not match those shown in the create table script]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#4963</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#4963</link>
				<pubDate><![CDATA[Thu, 13 Nov 2008 19:36:03]]> GMT</pubDate>
				<author><![CDATA[ bemall]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ Here are the steps I used to import GeoNames, PostalCodes, and Alternate Names into SQL 2005:

Used the utility on <a href='http://forum.geonames.org/gforum/posts/list/817.page' target='_new' rel="nofollow">http://forum.geonames.org/gforum/posts/list/817.page</a> to convert the files to UTF-16.

Utf8ToUtf16.exe allCountries.txt allCountriesUTF16.txt
Utf8ToUtf16.exe alternateNames.txt alternateNamesUTF16.txt
Utf8ToUtf16.exe allPostal.txt allPostalUTF16.txt (*I renamed the file to allPostal from allCountries.txt)

Next I created the tables.  I took the liberty of specifying nvchar for Unicoded fields and vchar for Latin based fields.  Also I increased the [Place Name] field in the Postal Codes to 200 length to match the [Name] field in GeoNames, not sure why there is a mismatch.

Here is the code I used to create the tables.
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>


/****** GeoNames ******/

CREATE TABLE &#91;dbo&#93;.&#91;GeoNames_tbl&#93;&#40;
	&#91;lGeoNameID&#93; &#91;int&#93; PRIMARY KEY,
	&#91;sName&#93; &#91;nvarchar&#93;&#40;200&#41;,
	&#91;sAsciiName&#93; &#91;nvarchar&#93;&#40;200&#41;,
	&#91;sAlternateNames&#93; &#91;nvarChar&#93;&#40;4000&#41;,
	&#91;fLatitude&#93; &#91;float&#93;,
	&#91;fLongitude&#93; &#91;float&#93;,
	&#91;sFeatureClass&#93; &#91;varchar&#93;&#40;1&#41;,
	&#91;sFeatureCode&#93; &#91;varchar&#93;&#40;10&#41;,
	&#91;sCountryCode&#93; &#91;varchar&#93;&#40;2&#41;,
	&#91;sAlternateCountryCodes&#93; &#91;varchar&#93;&#40;60&#41;,
	&#91;sAdmin1Code&#93; &#91;varchar&#93;&#40;20&#41;,
	&#91;sAdmin2Code&#93; &#91;varchar&#93;&#40;80&#41;,
	&#91;sAdmin3Code&#93; &#91;varchar&#93;&#40;20&#41;,
	&#91;sAdmin4Code&#93; &#91;varchar&#93;&#40;20&#41;,
	&#91;lPopulation&#93; &#91;bigint&#93;,
	&#91;sElevation&#93; &#91;bigint&#93;,
	&#91;sGtopo30&#93; &#91;bigint&#93;,
	&#91;sTimezone&#93; &#91;varchar&#93;&#40;50&#41;,
	&#91;dtModificationDate&#93; &#91;datetime&#93; NULL
&#41;


/****** Alternate Names ******/

CREATE TABLE &#91;dbo&#93;.&#91;GeoAlternateNames_tbl&#93;&#40;
	&#91;lAlternateNameID&#93; &#91;int&#93; PRIMARY KEY,
	&#91;lGeoNameID&#93; &#91;int&#93;,
	&#91;sISOLanguage&#93; &#91;nvarchar&#93;&#40;7&#41;,
	&#91;sAlternateName&#93; &#91;nvarchar&#93;&#40;200&#41;,
	&#91;sIsPreferredName&#93; &#91;char&#93;&#40;1&#41;,
	&#91;sIsShortName&#93; &#91;char&#93;&#40;1&#41; 
&#41;


/****** Postal Codes ******/

CREATE TABLE &#91;dbo&#93;.&#91;GeoPostal_tbl&#93;&#40;
	&#91;sCountryCode&#93; &#91;varchar&#93;&#40;2&#41;,
	&#91;sPostalCode&#93; &#91;varchar&#93;&#40;10&#41;,
	&#91;sPlaceName&#93; &#91;nvarchar&#93;&#40;200&#41;,
	&#91;sAdminName1&#93; &#91;nvarchar&#93;&#40;100&#41;,
	&#91;sAdminCode1&#93; &#91;varchar&#93;&#40;20&#41;,
	&#91;sAdminName2&#93; &#91;nvarchar&#93;&#40;100&#41;,
	&#91;sAdminCode2&#93; &#91;varchar&#93;&#40;20&#41;,
	&#91;sAdminName3&#93; &#91;nvarchar&#93;&#40;100&#41;,
	&#91;fLatitude&#93; &#91;float&#93;,
	&#91;fLongitude&#93; &#91;float&#93;,
	&#91;iAccuracy&#93; &#91;smallint&#93; NULL
&#41;

</pre>
		</div>

Using "SQL Server Import and Export Wizard" do the following.
Specify Flat File Source
Choose the source file. i.e. allCountriesUTF16.txt (You should see that Unicode is automatically checked, if the UTF8 to UTF 16 conversion was successful)
In the Columns section can the Column Delimiter to Tab and click Refresh (You should see that all the columns look correct without any strange 'tab' characters)
In the Advanced section (the most important) you need to specify the specifications for each field.
Use Suggest Types... option and change the number of rows to 1000 and click OK. (this is an optional step but it'll save some time)
Next use the table specifications to define each column.  For any integer field, I specified "eight-byte signed integer" . Also "Column 10" and the 11th field in GeoNames you need to specify Unicode String and length 20 as per the specifications, since "Suggest Types" defines it as a single-byte integer.
Once you have done all this, you can specify the destination, make sure you specify the destination table as the one you created since it will default to a new table using the file name. 
Hopefully, the data import will finish successfully.  Otherwise you may have to adjust you source column specifications (I missed some fields the first time I did this).

Good luck, I hope this helps :)


P.S. I'd have these pages open while you do the column specifications.
Link to GeoNames/Alternate Names specifications
<a href='http://download.geonames.org/export/dump/' target='_new' rel="nofollow">http://download.geonames.org/export/dump/</a>
Link to PostCodes specifications
<a href='http://download.geonames.org/export/zip/' target='_new' rel="nofollow">http://download.geonames.org/export/zip/</a>]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#5052</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#5052</link>
				<pubDate><![CDATA[Wed, 3 Dec 2008 20:39:54]]> GMT</pubDate>
				<author><![CDATA[ camerony]]></author>
			</item>
			<item>
				<title> Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ I am trying to do this in SQL 2008. Is there anything differently I should be doing. I have been having issues.]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#5071</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#5071</link>
				<pubDate><![CDATA[Sun, 14 Dec 2008 21:01:52]]> GMT</pubDate>
				<author><![CDATA[ rainmanjam]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ The program converted fine but I still had issues with the Import wizard. I finally go this to work using this table script and the BULK INSERT command::

CREATE TABLE GeoNames( 
      geonameid int NOT NULL, 
      name nvarchar(200) NULL, 
      asciiname nvarchar(200) NULL, 
      alternatenames nvarchar(max) NULL, 
      latitude float NULL, 
      longitude float NULL, 
      feature_class char(2) NULL, 
      feature_code nvarchar(10) NULL, 
      country_code char(3) NULL, 
      cc2 char(60) NULL, 
      admin1_code nvarchar(20) NULL, 
      admin2_code nvarchar(80) NULL, 
      admin3_code nvarchar(20) NULL, 
      admin4_code nvarchar(20) NULL, 
      population bigint NULL, 
      elevation int NULL, 
      gtopo30 int NULL, 
      timezone char(31) NULL, 
      modification_date date NULL 
) 
GO 



BULK 
  INSERT GeoNames 
      FROM 'C:\temp\outputFile.txt' 
            WITH( 
                  DATAFILETYPE = 'widechar', 
                  FIELDTERMINATOR = '\t', 
                  ROWTERMINATOR = '\n' 
                ) 
GO 


Hope this helps!!]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#5208</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#5208</link>
				<pubDate><![CDATA[Mon, 19 Jan 2009 03:58:28]]> GMT</pubDate>
				<author><![CDATA[ shelto]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ I'd like to post an update to this issue. You can use the 
<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
BULK 
INSERT GeoNames 
FROM 'C:\temp\outputFile.txt' 
WITH&#40; 
DATAFILETYPE = 'widechar', 
FIELDTERMINATOR = '\t', 
ROWTERMINATOR = '\n' 
&#41; 
GO 
</pre>
		</div>
to import the GeoNames and the GeoAlternateNames tables, but... to import the GeoPostal you have to use the Import Data...

Also, I modified the table structure as the geopostal table was missing a field, and the lat/lon need to be decimal(9, 6).

<span class="genmed"><b>Code:</b></span><br>
		<div style="overflow: auto; width: 100%;">
		<pre>
/****** GeoNames ******/
 
 CREATE TABLE &#91;dbo&#93;.&#91;GeoNames&#93;&#40;
 	&#91;GeoNameID&#93; &#91;int&#93; PRIMARY KEY,
 	&#91;Name&#93; &#91;nvarchar&#93;&#40;200&#41;,
 	&#91;AsciiName&#93; &#91;nvarchar&#93;&#40;200&#41;,
 	&#91;AlternateNames&#93; &#91;nvarChar&#93;&#40;4000&#41;,
	&#91;Latitude&#93; &#91;decimal&#93;&#40;9, 6&#41; NOT NULL
	&#91;Longitude&#93; &#91;decimal&#93;&#40;9, 6&#41; NOT NULL,
 	&#91;FeatureClass&#93; &#91;varchar&#93;&#40;1&#41;,
 	&#91;FeatureCode&#93; &#91;varchar&#93;&#40;10&#41;,
 	&#91;CountryCode&#93; &#91;varchar&#93;&#40;2&#41;,
 	&#91;AlternateCountryCodes&#93; &#91;varchar&#93;&#40;60&#41;,
 	&#91;Admin1Code&#93; &#91;varchar&#93;&#40;20&#41;,
 	&#91;Admin2Code&#93; &#91;varchar&#93;&#40;80&#41;,
 	&#91;Admin3Code&#93; &#91;varchar&#93;&#40;20&#41;,
 	&#91;Admin4Code&#93; &#91;varchar&#93;&#40;20&#41;,
 	&#91;Population&#93; &#91;bigint&#93;,
 	&#91;Elevation&#93; &#91;bigint&#93;,
 	&#91;Gtopo30&#93; &#91;bigint&#93;,
 	&#91;Timezone&#93; &#91;varchar&#93;&#40;50&#41;,
 	&#91;ModificationDate&#93; &#91;datetime&#93; NULL
 &#41;
 
 
 /****** Alternate Names ******/
 
 CREATE TABLE &#91;dbo&#93;.&#91;GeoAlternateNames&#93;&#40;
 	&#91;AlternateNameID&#93; &#91;int&#93; PRIMARY KEY,
 	&#91;GeoNameID&#93; &#91;int&#93;,
 	&#91;ISOLanguage&#93; &#91;nvarchar&#93;&#40;7&#41;,
 	&#91;AlternateName&#93; &#91;nvarchar&#93;&#40;200&#41;,
 	&#91;IsPreferredName&#93; &#91;char&#93;&#40;1&#41;,
 	&#91;IsShortName&#93; &#91;char&#93;&#40;1&#41; 
 &#41;
 
 
 /****** Postal Codes ******/
 
 CREATE TABLE &#91;dbo&#93;.&#91;GeoPostal&#93;&#40;
 	&#91;CountryCode&#93; &#91;varchar&#93;&#40;2&#41;,
 	&#91;PostalCode&#93; &#91;varchar&#93;&#40;10&#41;,
 	&#91;PlaceName&#93; &#91;nvarchar&#93;&#40;200&#41;,
 	&#91;AdminName1&#93; &#91;nvarchar&#93;&#40;100&#41;,
 	&#91;AdminCode1&#93; &#91;varchar&#93;&#40;20&#41;,
 	&#91;AdminName2&#93; &#91;nvarchar&#93;&#40;100&#41;,
 	&#91;AdminCode2&#93; &#91;varchar&#93;&#40;20&#41;,
 	&#91;AdminName3&#93; &#91;nvarchar&#93;&#40;100&#41;,
 	&#91;AdminCode3&#93; &#91;varchar&#93;&#40;20&#41;,
	&#91;Latitude&#93; &#91;decimal&#93;&#40;9, 6&#41; NOT NULL
	&#91;Longitude&#93; &#91;decimal&#93;&#40;9, 6&#41; NOT NULL,
 	&#91;Accuracy&#93; &#91;smallint&#93; NULL
 &#41;
</pre>
		</div>]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#8621</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#8621</link>
				<pubDate><![CDATA[Sat, 23 Oct 2010 20:00:47]]> GMT</pubDate>
				<author><![CDATA[ rickrat]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ I've updated the accuracy of the US zip codes, to be the exact north/south point (to 6 decimal places) on the globe of the centroid or "middle" of the US Postal Code.

This is a sql script for sql server 2005-2008.

<a href='http://www.compdj.com/dl.aspx?f=Temp/UpdateGeoPostalUSAccuracy.zip' target='_new' rel="nofollow">http://www.compdj.com/dl.aspx?f=Temp/UpdateGeoPostalUSAccuracy.zip</a>

Comes with no warranties, etc.

Enjoy!

Rick]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#8622</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#8622</link>
				<pubDate><![CDATA[Sat, 23 Oct 2010 20:35:28]]> GMT</pubDate>
				<author><![CDATA[ rickrat]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ If anyone of you guys ever come across the following SQL Server error while using BULK INSERT to load data into tables:

"Bulk load: DataFileType was incorrectly specified as widechar. DataFileType will be assumed to be char because the data file does not have a Unicode signature."

and the steps available to covert a UTF-8 file type to UTF-16 file type as listed in one of the blogs posted by mark right in the begining weren't helpful enough to resolve the issue THEN following blog might be useful to you.

http://aliiraza.wordpress.com/?p=103&preview=true

few simple steps listed to convert UTF-8 to UTF-16 using SQL Server Management Studio.

hope it helps!]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#11551</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#11551</link>
				<pubDate><![CDATA[Wed, 6 Jun 2012 06:25:01]]> GMT</pubDate>
				<author><![CDATA[ shigarr]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ getting Geo locations into db is a little tricky here is a great tutorial:

http://taylor.woodstitch.com/php/php-mysql-best-solutions-for-finding-points-in-a-polygon-from-a-database/]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#12043</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#12043</link>
				<pubDate><![CDATA[Tue, 4 Dec 2012 06:01:03]]> GMT</pubDate>
				<author><![CDATA[ antiochIst]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ As of SQL 2014, UTF-8 is supported, and it's no longer needed to convert to UTF-16.
I successfully imported the file via a bulk insert task in SSIS

-Ethan]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#43687</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#43687</link>
				<pubDate><![CDATA[Thu, 2 Feb 2017 11:40:31]]> GMT</pubDate>
				<author><![CDATA[ ethan1701]]></author>
			</item>
			<item>
				<title>Re: Import GeoNames dump into SQL Server</title>
				<description><![CDATA[ Hi, everyone!
I just created project, that helps automaticaly import TXT files to MS SQL Server. https://github.com/jonilviv/GeoNames.org]]></description>
				<guid isPermaLink="true">http://forum.geonames.org/gforum/posts/list/847.page#44645</guid>
				<link>http://forum.geonames.org/gforum/posts/list/847.page#44645</link>
				<pubDate><![CDATA[Mon, 20 Nov 2017 18:03:23]]> GMT</pubDate>
				<author><![CDATA[ jonilviv]]></author>
			</item>
	</channel>
</rss>