I know this is not the exact solution to the question above, but for me, it was a nightmare when I was trying to Copy data from one database located at a separate server to my local.
I was trying to do that by first export data from the Server to CSV/txt
and then import it to my local table.
Both solutions: with writing down the query to import CSV
or using the SSMS Import Data wizard was always producing errors (errors were very general, saying that there is parsing problem). And although I wasn't doing anything special, just export to CSV
and then trying to import CSV
to the local DB
, the errors were always there.
I was trying to look at the mapping section and the data preview, but there was always a big mess. And I know the main problem was comming from one of the table
columns, which was containing JSON
and SQL
parser was treating that wrongly.
So eventually, I came up with a different solution and want to share it in case if someone else will have a similar problem.
What I did is that I've used the Exporting Wizard on the external Server.
Here are the steps to repeat the same process:
1) Right click on the database and select Tasks -> Export Data...
2) When Wizard will open, choose Next and in the place of "Data Source:" choose "SQL Server Native Client".
In case of external Server you will most probably have to choose "Use SQL Server Authentication" for the "Authentication Mode:".
3) After hitting Next, you have to select the Destionation.
For that, select again "SQL Server Native Client".
This time you can provide your local (or some other external DB
) DB
.
4) After hitting the Next button, you have two options either to copy the entire table from one DB
to another or write down the query to specify the exact data to be copied.
In my case, I didn't need the entire table (it was too large), but just some part of it, so I've chosen "Write a query to specify the data to transfer".
I would suggest writing down and testing the query on a separate query editor before moving to Wizard.
5) And finally, you need to specify the destination table where the data will be selected.
I suggest to leave it as [dbo].[Query]
or some custom Table
name in case if you will have errors exporting the data or if you are not sure about the data and want further analyze it before moving to the exact table you want.
And now go straight to the end of the Wizard by hitting Next/Finish buttons.
BULK NSERT
or don't have permissions for it). – Denis