Solved

Alter Table Problem - over 125 million rows in table and query takes to long.

Posted on 2010-09-06
4
319 Views
Last Modified: 2013-11-10
Hi,
I have a table with 125million rows in it on the live db
i replicate ths db to a mysql db daily
For reporting reaons, i want to pull in the data from this table into my SQL SERVER db.
i only pull in the previous days entries to the SQL SERVER.

however to do this i want to add a colunm called DW_TIMESTAMP

So i would use this syntax
ALTER TABLE MYTABLENAME
ADD COLUMN dw_timestamp TIMESTAMP
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

however because there are soo many rows this is taking forever, in fact it stopped the Mysql server because i believe it timmed out.

Can anyone suggest how i can speed up this process.

I was thinking if i could add a where clause but i don't believe that would work.

Kind Regards,
Putoch
0
Comment
Question by:Putoch
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33610603
please clarify: is this MS SQL Server, or MySQL?
which version / sp ?

this "alter table" should not take "forever", unless it's blocked all the time by other processes issuing schema locks on the table ...
0
 
LVL 40

Expert Comment

by:RQuadling
ID: 33610616
Maybe if you add the column, allowing nulls first.

Then assign the default value as a separate transaction.

If this is a always live DB, then you may just have to wait it out. You should only need to do it once.

0
 

Author Comment

by:Putoch
ID: 33616711
Its a MYSQL db (version 5.1.44 )

i was able to alter any other table i needed to with out any trouble, it seems to only be this table.
i will try to do it seperatly now and see how this works.

Something strange though happened with the other tables.
i set up the timestamp to Default current_timestamp on update.
however when i updated all those other tables the timestamp defaulted to 0000-00-00.

Why would this happen do you know?
Is there something i'm missing on my syntax.
the timestamp is set up as NOT NULL.

ALTER TABLE MYTABLENAME
ADD COLUMN dw_timestamp TIMESTAMP
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

Thanks a million,
putoch
0
 
LVL 1

Accepted Solution

by:
colin_o_brien earned 500 total points
ID: 34053516
you could try renaming the table,  adding the new column using a SELECT INTO statement into MYTABLENAME, and then re-adding whatever indexes/constraints you have.  
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

It is helpful to note: This is a cosmetic update and is not required, but should help your reports look better for your boss.  This issue has manifested itself in SSRS version 3.0 is where I have seen this behavior in.  And this behavior is only see…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

937 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now