Solved

Convert Anywhere Autoincrement to SQL Server 11 IDENTITY

Posted on 1997-11-07
4
492 Views
Last Modified: 2012-06-27
I have a table created on Sybase SQL Anywhere, where is Autoincrement column (for ex. named 'empid'). I need to import data to Sybase SQL Server 11 to a table with the same structure.

Problem: I don't know how to do it, because I need to convert 'empid' with original (Anywhere) values. When I tried it (using PB5.0.02), data converted succesfully, but values in 'empid' were different!

Thanks for your help.
0
Comment
Question by:honza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:RONY
ID: 1098064
That's logic, when you define a autoincrement colom it increments each time you insert a line. I suppose that in your old table you did some delete allso. This delete will give 'wholes' in your increment colom. When you now import your data in a new table this increment will be filled nicely without wholes in it, wich explains that they haven't the same values as in the old table. Set the colom type of your new table to integer (not increment) and you will have the same values in your new table

0
 

Author Comment

by:honza
ID: 1098065
You are right, i did some deletes, but it's not new for me. I need to import old data to new table where is identity too! To create integer column doesn't solve my problem.
Original Sybase documentation says: '...set identity_insert tablename on and you will be able to insert data manualy to identity column...', but it doesn't work from PB, I tried it. It works only from ISQL but I need insert about 100000 rows, I have to create sql script. How? Save Rows As SQL from datawindow creates syntax for inserting into Anywhere - I need syntax for SQL Server 11. Search and Replace ';' to ' go ' from WordPad??? Hahaha! Never finished. Please think and help! Thank you for answer.
0
 
LVL 10

Accepted Solution

by:
bret earned 50 total points
ID: 1098066
Use bcp to copy the data out of SQL Anywhere and into SQL Server.

BCP uses the "-E" flag to preserve the existing identity column values from the bcp file; here is the explanation from the Utility Programs booklet entry on BCP:

"E"- explicitly specifies the value of a table's IDENTITY column.
By default, when you bulk copy data into a table with an
IDENTITY column, the host file must contain a placeholder for
the IDENTITY column (a value of 0 is recommended). The
server assigns the row a unique, sequential IDENTITY column
value, as bcp inserts each row into the table. If the number of
inserted rows exceeds the maximum possible IDENTITYcolumn
value, SQL Server returns an error message.
To use an explicit IDENTITY column value from the host file for
each row, specify the -E flag when copying data into a table.
The -E option has no effect on bulk copying out.

-bret
0
 

Author Comment

by:honza
ID: 1098067
Thanks for your help. It's perfect!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The conference as a whole was very interesting, although if one has to make a choice between this one and some others, you may want to check out the others.  This conference is aimed mainly at government agencies.  So it addresses the various compli…
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question