Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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, June 27, 2014 1:04 AM
Points: 717, Visits: 538
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 @ 7:08 AM
Points: 12,864, Visits: 31,711
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1441654
Posted Friday, April 12, 2013 6:09 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 7:08 AM
Points: 12,864, Visits: 31,711
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

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1441658
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse