Solved

Convert Anywhere Autoincrement to SQL Server 11 IDENTITY

Posted on 1997-11-07
4
480 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Is your company's data protection keeping pace with virtualization? Here are 7 dynamic ways to adapt to rapid breakthroughs in technology.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now