Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing field to identity

Status
Not open for further replies.

hmckillop

Programmer
Oct 30, 2001
1,540
GB
I have to change a integer field to be an identity. This isnt a big problem, the issue is I have 65 Million rows in the table and need the most efficient way of changing this over. The table has 3 indexes (inc clustered)
I have tried BCPing the data out, truncating tha table, amending the field structure and then repopulating via bcp but I am getting PK_Violation on insert.
I have tried using the script build by SQL Enterprise which basically creates atemp table of the correct structure, inserts into it and then rebuilds the indices - this takes about 7 hrs.

If anyone has done anything similiar and found the most efficient way, any help much appreciated.
Thanks


"I'm living so far beyond my income that we may almost be said to be living apart
 
This is a perfect application for this thread's technique: Updating Rows with Row Count
thread183-980264 (assuming that you have a suitable column to use for sorting and that you have enough space to create a 2nd table of equal size).
Don't update rows, but rather insert them into a new table in groups.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top