MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old February 12th, 2004, 08:49 AM
Divit Divit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Netherlands
Posts: 4 Divit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question Keep performance high

I always ssem to want things I cannot find in books about the subject.

Here's my challenge!

I've created a MsAccess Frontend/MsSQL backend for a callcenter. In the Main table there are more than 200.000 records so I want to nibble from the botton and put let's say 100.000 records in a new table (and delete in the main). But I want this new table with the backup records to be in a new database so I can create an new frontend to search in the history-records.
Every month I woul like to take of the main table some 20.000 records because that's the monthly average in growth and paste these records in the backup table in the ohter database. So performance is no issue and history is maintained.

Anybody with any ideas or pointer to solutions? All is appreciated highly.

Reply With Quote
  #2  
Old February 12th, 2004, 09:27 AM
Jaredke Jaredke is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 4 Jaredke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If this is something you want run monthly you could set it up on your SQL Server as a Job. This will allow you to write a query that will transfer the data you want, plus remove the data after it has been transferred while allowing SQL Server to execute this job at the necessary time.

Reply With Quote
  #3  
Old February 12th, 2004, 09:36 AM
Divit Divit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Netherlands
Posts: 4 Divit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's exactly want I want but unfortunately am not able to do myself so i'm looking for examples on how to do this

I've created the BCK-DB manually and I've restored a backup from the production db into the backup-db to test things.
I'm relatively new to this kind of SQLServer stuff.

Reply With Quote
  #4  
Old February 17th, 2004, 08:56 AM
Ultrasonik Ultrasonik is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Cleveland
Posts: 7 Ultrasonik User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
To create a job:

In the Enterprise Manager...
Expand the Server/Management/SQL Server Agent
Right click on Jobs and choose New Job
Give it a name and then click the "Steps" tab
Click the New Step Button
Give it a name
Type should be Transact-SQL Script
Select the proper database in the Database drop down
In the Command text box put your SQL. It would go something like this:

INSERT INTO backuptable SELECT TOP 100000 * FROM livetable ORDER BY identityfield desc;

DELETE FROM livetable WHERE identityfield IN (SELECT TOP 100000 * FROM livetable ORDER BY identityfield desc);

Click Ok and then Choose the Schedule Tab.
Click the New Schedule button to set a time for this to run.

I hope that helps. Make sure to try this on test tables first. If for some reason the INSERT fails but the DELETE doesn't you'll be either grateful for having a good backup routine or kicking yourself for not.

Reply With Quote
  #5  
Old February 18th, 2004, 05:32 AM
Divit Divit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Netherlands
Posts: 4 Divit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok,
I've succeeded in copying rows from and into with;
insert into PSCBCK.dbo.tblLeeg2 select top 10 * from PSCBCK.dbo.TblAlles order by volgnummer

But if I try your second command it results in an error.

When I try to a
Delete from PSCBCK.dbo.TblAlles select top 10 it deletes all the records

So any more tips are welcome and if you can recommend a book on MsAccess/SQL I'm looking forward to reading them.

Divit

Reply With Quote
  #6  
Old February 18th, 2004, 11:07 AM
saodl saodl is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Los Angeles, CA
Posts: 21 saodl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The problem with his second query is the *. If your going to use an "IN" like that, you need to do a query that returns 1 column. So it's

DELETE FROM livetable WHERE identityfield IN (SELECT TOP 100000 identityfield FROM livetable ORDER BY identityfield DESC;

However you may find that a "WHERE identityfield IN ([list])" query with a list of 100000 is just a little innefficient. It should be a lot faster to say

DELETE FROM livetable WHERE identityfield >= (SELECT TOP 1 identityfield FROM backuptable ORDER BY identityfield ASC);

That is, you select the value of the identityfield of the 100000th row (the last row, which should be the lowest- or highest, depending on how your identityfield is organized and assigned) that you just inserted into the backup field, and delete everything greater than that (all of which you just backed up).

Reply With Quote
  #7  
Old February 23rd, 2004, 04:40 AM
Divit Divit is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Netherlands
Posts: 4 Divit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for your help. I've succeeded in deleting the rows I've copied first to the other table. The code is on another machine but I've deleted all the records with the same identity-number, using it in the subquery.

Now on to get it all organised in a nice scheduled job.

Divit

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Keep performance high


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway