71

I want to move data from one DB to another, while keeping the identity column values in the old DB. When I run the wizard I get a validation error "Failure inserting into the read-only column "ChannelID".

Where ChannelID is an identity column on that table. How can I override the identity functionality in order to be able to import the data?

7 Answers 7

123

You'll need to Enable identity insert. There's a check box when you click the Edit Mappings.

6
  • 3
    SET IDENTITY INSERT ON works too, however the question was about using the wizard.
    – House
    May 5, 2011 at 6:48
  • +1 you were more specific. And thanks for the update to the link, sometimes i forgot to switch to English.
    – il_guru
    May 5, 2011 at 8:51
  • 6
    It appears you have to do this for every single table that requires it. The wizard tool sucks!
    – ATL_DEV
    Sep 7, 2013 at 18:44
  • 8
    You can select all columns in the wizard, edit mapping, and check enable identity insert (at least in SSMS 2012).
    – Tim Lehner
    Jun 27, 2014 at 14:26
  • Will this also update the identity seed or would I need to reseed?
    – Toolsmythe
    Aug 4, 2016 at 22:22
10

Byte56's answer is correct - check "Enable identity insert" from the Edit Mappings screen. I just wanted to point out that the "Select Source Tables and Views" list supports multi-select, so you can hold down Shift or Ctrl to select multiple tables in the list.

9

In EDIT COLUMN MAPPINGS, Tick ENABLE IDENTITY INSERT. Then click EDIT SQL button.

Change

[MyID] int NOT NULL,

into

[MyID] int IDENTITY(1,1),

Works in importing MS Access database. This preserves the data in Autonumber field being converted to Identity column.

5

You should use SET IDENTITY INSERT ON to allow the insert of values in an IDENTITY column

Here is a link to MSDN

2
  • 1
    I did that. It did not apply to the Wizard apparently. Byte56' solution did the trick. Thank you. May 5, 2011 at 9:12
  • 1
    The import export wizard ignores this. It does need to be set in the wizard itself.
    – Anigel
    Jan 9, 2015 at 10:24
4

SQL Server 2008 R2 using SSMS 2008 R2.

Simply enabling identity on the "Edit Mappings" does not retain identity=true. I have to manually edit the sql for each table and include the IDENTITY property in the sql code.

Example: ADD MS_IDENT numeric(18,0) IDENTITY NOT NULL,

1
  • This works but does not necessarily preserve the row order. Aug 26, 2019 at 8:53
4

I just upgraded to SQL Server Management Studio 2017. I tried checking the "Use identity" checkbox in the Edit Mappings dialog but this did not work. When updating an existing table, the wizard doesn't let you edit the SQL. Instead, I was able to save it as a package on my hard drive. I then edited the file in Notepad, searching for "identity". Sure enough, the property was set to true, which according to the comments within the file itself, means the value for the identity column is copied from the source. Changing it to false results in the value being auto generated in the destination. Hope this helps.

0

I have spent some time trying to find a solution for this

I have an access database with 300+ tables and using SSMS2017 import tool I could not get it to preserve the primary key and auto number, without manually editing the config for each table.... not good..

In the end I used a tool made by bullzip, (MS Access to MSSQL) which allows me to convert from access to mssql (they also have a tool for access to MySQL)

the tool does the job for you, wither to a script if you have a small table, or directly to the server..

All ID's are intact and autonumbers are also in there..

job done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.