简体   繁体   中英

SQL Server 2008 R2 Data Export Problems

I am trying to export data from my production DB to my development DB but I am getting this error:

Messages Error 0xc0202049: Data Flow Task 1: Failure inserting into the read-only column "id". (SQL Server Import and Export Wizard)

Is there a way to check which column is that because I have 20 tables that all of them use the column name id or at least get a better error report?

Just click on Edit mappings when you choose tables to import from and to. and check on the Enable identity insert checkbox. And you should do that for each choosen table. Then you can complete your import. It was helped me in the same situation.

If the column ID is an identity column, it's likely set up to generate automatically when a row is inserted, and is not able to be directly written to.

To preserve linking from the production environment to the test, use:

SET Identity_Insert <TableName> ON

To allow you to write identity values.

All I had to do was:

  • Right-click on the column (in this case 'ID')
  • Select Modify
  • Inside the Column Properties scroll down until you see Identity Specification
  • Expand the view and select NO from the drop down menu.

If anyone knows a different (faster) way of doing this please share

听起来好像你可能试图将值插入已声明为IDENTITY字段的列中。

Well, the answer is a bit late but I'm posting it anyway for the sake of providing to community.

I assume that you are trying to copy tables (not partial data). My answer is based on this assumption.

  1. Connect to the source db via Object Explorer in SSMS.
  2. Right click the db that you want its tables to be copied.
  3. Go to 'Tasks' --> 'Export' .
  4. Choose your source and destination server and if you don't want additional script to be run before hands just press next ('Copy data from one or more tables or views'). Now you may select tables you want to be copied to the destination.

Select tables that you want to be completely copied to the destination. And click on 'edit mappings'. Here you may 'enable identity insert'. You will also have other options so check the screen before pressing OK.

If you do not use an express edition of SSMS here you may create an SSIS package to create jobs and to automatize this process in the future. You may check 'run immediately' and follow the screen about how it goes with all the warnings and errors. Hopefully you will get none. Good luck!

Tested with:
(
    Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86) 
    Jun 17 2011 00:57:23 
    Copyright (c) Microsoft Corporation
    Enterprise Edition on Windows NT 5.2 <X86> (Build 3790: Service Pack 2)
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM