Solved

Convert Anywhere Autoincrement to SQL Server 11 IDENTITY

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

14 Experts available now in Live!

Get 1:1 Help Now