Export data not taking foreign key relationships into account

Discussion of open issues, suggestions and bugs regarding database management and development tools for SQL Server
Post Reply
ori_g
Posts: 11
Joined: Thu 22 Jun 2017 17:26

Export data not taking foreign key relationships into account

Post by ori_g » Tue 18 Jul 2017 14:26

I am using the Export Data functionality in Studio to export my entire database data via a single SQL Script.

The challenge I'm finding is that some of my tables have foreign key relationships to other tables, but the script created isn't taking that into account - So, for example, I have Table B that has a foreign key to a column in Table A (which would mean Table A needs to be populated first), but the script has Table B being populated before Table A and, therefore, it is causing a SQL error due to the data not being present in Table A yet.

Any thoughts about how to ensure the "parent" tables are populated before the tables that rely on their data?

alexa

Re: Export data not taking foreign key relationships into account

Post by alexa » Wed 19 Jul 2017 08:53

You can use the 'Generate Scripts' feature (select 'Database -> Tasks -> Generate Scripts...' from the main menu) where you can select the 'Data' option only on the 'Script content' page of the generate scripts wizard. This way, dependencies will be taken into account.

ori_g
Posts: 11
Joined: Thu 22 Jun 2017 17:26

Re: Export data not taking foreign key relationships into account

Post by ori_g » Wed 19 Jul 2017 16:29

That gives me the same functionality as SSMS, but I lose the ability to create Merge statements.
Is there a way to have this functionality of knowing dependants AND be able to get the scripts written as Merge?

alexa

Re: Export data not taking foreign key relationships into account

Post by alexa » Thu 20 Jul 2017 12:50

We will support this functionality in one of the next product versions.

Post Reply