Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Bulk Update??? Expand / Collapse
Author
Message
Posted Thursday, April 11, 2013 9:41 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Friday, April 15, 2016 10:16 PM
Points: 755, Visits: 582
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.
Post #1441560
Posted Friday, April 12, 2013 6:04 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 12:53 PM
Points: 14,433, Visits: 37,807
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!
Post #1441654
Posted Friday, April 12, 2013 6:09 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 12:53 PM
Points: 14,433, Visits: 37,807
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!
Post #1441658
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse