Migrating data from Access to SQL Server

Suppose that you have a simple Microsoft Access database that you need to migrate to another database such as MS SQL Server. You model the tables and relationships in the new database, and now you need to export the actual data from Access and import it into the new database. This is how I did it:

I began by exporting the data as CSV. I found the easiest way was to simply use copy/paste. First though, open each tables in Design View. There is a tab named “Lookup” at the bottom. Ensure that any lookup field is set to display “Value List” instead of “Table/Query”. Then you can view the table normally and copy all data to the clipboard (Ctrl+A, Ctrl+C) and paste it into a .csv text file saved with UTF-8 encoding.

Next I used PowerShell to transform the CSV data into to SQL statement. While doing this I also adapted the structure of the data. For example, some fields were renamed, and I also had multiple fields that I wanted to merge into one. Here is a generic version of the script I put together that you can modify to your own needs:

Note: Normally you let SQL Server generate the ID of key fields. In this case though, we already have ID:s from the Access database. Since these ID:s specify the primary-foreign key relations, it is important to keep intact. To allow insertion of keys like that, IDs SET IDENTITY_INSERT Chemicals ON  is used.

Finally, open the generated SQL script (provisioning.sql) in SQL Server Management Studio (or similar) and run it to provision your data!

This entry was posted in Development, Tutorials and tagged , , , , , , . Bookmark the permalink.

One Response to Migrating data from Access to SQL Server

  1. A Fan says:

    Hello, I’m sorry to write this here,

    Today I was looking for a program in my PC and trying to remember its name my brain immediately said “Artgem” (I was actually thinking in ArtRage) and it made me remember those glorious days when I was a kid and I used your program to do amateur pixelated sprites for my really amateur private games.

    It really was (or is) a great tool. I wonder why is discontinued instead of been made freeware?

    I hope all the developers are doing great these days. Stay healthy my friends!

Leave a Reply

Your email address will not be published. Required fields are marked *