Renumbering the Table IDENTITY Columns with bcp

If the table does not contain IDENTITY columns used for referential integrity, and if there are gaps in the numbering sequence, you can renumber the IDENTITY column to eliminate gaps, which allows more room for insertions.

  1. From the operating system command line, use bcp to copy out the data:
    bcp pubs2..mytitles out my_titles_file -N -c

    where -N instructs bcp not to copy the IDENTITY column values from the table to the host file, and -c instructs bcp to use character mode.

  2. In SAP ASE, create a new table that is identical to the old table.
  3. From the operating system command line, use bcp to copy the data into the new table:
    bcp pubs2..mynewtitles in my_titles_file -N -c

    where -N instructs bcp to have SAP ASE assign the IDENTITY column values when loading data from the host file, and -c instructs bcp to use character mode.

  4. In SAP ASE, drop the old table, and use sp_rename to change the new table name to the old table name.

If the IDENTITY column is a primary key for joins, you may need to update foreign keys in other tables.

By default, when you bulk-copy data into a table with an IDENTITY column, bcp assigns each row a temporary IDENTITY column value of 0. As it inserts each row into the table, the server assigns it a unique, sequential IDENTITY column value, beginning with the next available value. To enter an explicit IDENTITY column value for each row, specify the -E flag. See the Utility Guide.