?
Solved

Convert Anywhere Autoincrement to SQL Server 11 IDENTITY

Posted on 1997-11-07
4
Medium Priority
?
494 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 200 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

801 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