Solved

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

Posted on 2010-09-06
4
323 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 143

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:Richard Quadling
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using rowversion for incremental load of datawarehouse. 12 37
When are cursors useful? 8 62
sql server query 9 28
T-SQL Query 5 25
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

710 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