Importing data without over-writing existing identity seeds

  • Hi,

    I need to import data from an Access mdb into existing SQL tables where the Identity Seed values in the SQL tables (numeric primary keys) retain the same value as the corressponding records in the Access tables.

    Is this as simple as setting the 'Is Identity' property to 'No' prior to the import and then to 'Yes' on completion? These are incremental integers (Start at 1 and increment by 1), so I'm guessing that the Identity Increment and Identity Seed values will both be set to '1'.

    Or is there anything I should be aware of?

    I have already tried the above (Setting the 'Is Identity' property to 'No') via the Import wizard. But the procedure failed as Error 0xc020249 'Failure inserting into the read-only column 'adIndex'.

    Note:

    There may be instances where there are no values (Null) in the Access tables. Is this likely to cause an error?

    Thanks in advance,

    Neal

  • You can issue the command Set Identity_Insert [TableName] On before you start the insert and then Set Identity_Insert [TableName] Off when you are done.

    Yes, nulls will cause a problem because Identity Columns do not allow NULLs.

  • It's Ok... I found out how to resolve this (I hope).

    On the Import Wizard, there is a setting on the Column Mappings called Enable identity insert. Select this tick-box.

    Microsoft definition:

    Choose this option to allow existing identity values in the source data to be inserted into an identity column in the destination table. By default, the destination identity column does not allow this.

    See http://msdn.microsoft.com/en-us/library/ms189660.aspx

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply