Solved

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

Posted on 2010-09-06
4
322 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 15 50
Freeze portion of datamart 2 21
Logical Operator should return Integer value in SSIS 9 34
SQL Server Compression Decision 5 37
A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
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.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

740 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