Solved

Convert Anywhere Autoincrement to SQL Server 11 IDENTITY

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 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