Glowworm27
Programmer
Hello all,
we have a SQL database that is populated with data from an Oracle database for website stuff. I did not write the queries that get the data, a former developer wrote them, and we have been having a little troulbe with the transacation logs and some other things. Which is how I got involved.
The SQL jobs run and refresh the data every 30 minutes.
The jobs consist of the following query (greatly reduced for the web, but in a sense this is what it does.)
I was thinking that this is a very huge waste of resources and bandwidth and I should optimize the jobs and queries to reduce bandwidth, time and resources.
an optimized query would do something like this
obviously i would fix up the syntax so it would be correct but I think you get the idea.
Instead of truncating the table each time the job runs, and inserting 90 days worth of data. (which can be approx 30,000 rows)
Delete the data older than 90 days from mytable
and get the data from the oracle database newer than the data in mytable
as an FYI there are 7 jobs just like this that run to fill several tables, and they run every 30 minutes.
George Oakes
CEO & President
COPS Software, Inc.
Programmer & Developer
.Net, WSS 3.0, SQL DBA
Check out this awsome .Net Resource!
we have a SQL database that is populated with data from an Oracle database for website stuff. I did not write the queries that get the data, a former developer wrote them, and we have been having a little troulbe with the transacation logs and some other things. Which is how I got involved.
The SQL jobs run and refresh the data every 30 minutes.
The jobs consist of the following query (greatly reduced for the web, but in a sense this is what it does.)
Code:
Begin transacation
Truncate Table mytable
Insert into mytable(
Select * from oracledatabase where addtime > sysdate -90
)
if @@trancount >0
Commit transaction
I was thinking that this is a very huge waste of resources and bandwidth and I should optimize the jobs and queries to reduce bandwidth, time and resources.
an optimized query would do something like this
Code:
begin transaction
delete mytable where addtime < dateadd(day, -90, now())
insert into mytable(
Select * from oracledatabase where addtime > (Select Max(addtime) from mytable)
)
if @@trancount > 0
Commit transacation
obviously i would fix up the syntax so it would be correct but I think you get the idea.
Instead of truncating the table each time the job runs, and inserting 90 days worth of data. (which can be approx 30,000 rows)
Delete the data older than 90 days from mytable
and get the data from the oracle database newer than the data in mytable
as an FYI there are 7 jobs just like this that run to fill several tables, and they run every 30 minutes.
George Oakes
CEO & President
COPS Software, Inc.
Programmer & Developer
.Net, WSS 3.0, SQL DBA
Check out this awsome .Net Resource!