SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Bulk Update???


Bulk Update???

Author
Message
T.Ashish
T.Ashish
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1359 Visits: 607
Hi All,

I have a table with more than 50 Million records.

I am changing a PK column into identity.
First I am droping all indexes and constraints then script to change datatype.

Even after 5 hours, process is not complete.

Can you suggest me some solution.

Thanks.
Lowell
Lowell
SSC Guru
SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)

Group: General Forum Members
Points: 72084 Visits: 40942
50 millions rows of data is not really that much data. it sounds like you are being blocked. exclusive schema locks, data , etc.

this is my suggestion what you should do instead:
1. script the table via SSMS with all the constraints and all indexes.
2. modify the script to have a slightly different name, ie CREATE TABLE OriginalName_TMP
3. modify the script to have the new identity field you want.
4. create the table by running the modified script.
5. rename the original table so people can no longer access it(sp_rename 'dbo.OriginalName','OriginalName_SAV')
6. Insert the data into the table with the new structure (INSERT INTO OriginalName_TMP(ColumnList) .... SELECT ColumnList FROM OriginalName_SAV)
7. rename the tmp table to the original name sp_rename 'dbo.OriginalName_TMP','OriginalName'

Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Lowell
Lowell
SSC Guru
SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)SSC Guru (72K reputation)

Group: General Forum Members
Points: 72084 Visits: 40942
now that i had a sip of coffee, it's even easier:

create the new table on the fly:

--script out the constraints and indexes from the original table

--create the new table instantly with the data and the identity column.
SELECT
identity(bigint,1,1) AS NewColumnName,
ColumnList
INTO OriginalName_TMP
FROM OriginalName
--rename the original
EXECUTE sp_rename 'dbo.OriginalName','OriginalName_SAV'
--rename the new table to teh right name
EXECUTE sp_rename 'dbo.OriginalName_TMP','OriginalName'
--modify the constraint script to have unique names for the new table and run them
ALTER TABLE ADD CONSTRAINT UQ_...
CREATE INDEX....



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search