• Blog posts

    Bio

    By David Crowther 

    64.png

    Question:

    I would like to copy a PostGIS Database Table into a SQL Server Database, what are the best steps to do this?

    Answer:

    In the blog below, I have outlined how to use Ogr2Ogr to load a Shapefile into a SQL Database. This is a good starting point for learning how to use OgrOgr.

    https://www.cadlinecommunity.co.uk/hc/en-us/articles/360000275789-QGIS-How-do-you-load-and-then-access-SQL-Server-Spatial-data-within-QGIS-

    Using this updated Ogr2Ogr script below, you can also copy an existing PostGIS Database table into your SQL Database:

    ogr2ogr -OVERWRITE -f "MSSQLSpatial" "MSSQL:server=SERVERNAME;database=SQLDBNAME;trusted_connection=yes;driver=SQL Server" PG:"host=SERVERNAME port=5432 user='userid' password='password' dbname='PostGISDBNAME'" -sql "SELECT * from mways" -SkipFailures -nln "UK_Motorways".

    The above script will copy the PostGIS Database Table called ‘mways’ and insert it into your SQL Database as a table named – ‘UK_Motorways’.