Solved

Deleting records from 2 tables vfp

Posted on 2013-05-23
5
509 Views
Last Modified: 2013-05-23
Hi:
I am running a capacity planning database. This copies all relevant records from oracle and stores them in a table called capacity. The copy routine is run several times a day, and the capacity is seen to rise as orders are added to oracle. I can report that at say 8am there were 5000 orders and at 5pm there were 5500 but have been challenged to provide details.
My solution is to create a copy of the capacity table (called lastcap) before the update, and again after (called thiscap). What I need to do is 'remove'  those records that are in both tables (or read only those that are in the later table). Does anybody know the best way of achieving this?
Thanks!
0
Comment
Question by:ClaytonGlass
[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
5 Comments
 
LVL 42

Accepted Solution

by:
pcelba earned 250 total points
ID: 39191063
Each table record should have its own unique ID, e.g OrderID. This is the only requirement for the following query:

SELECT * FROM Capacity
WHERE OrderID NOT IN (SELECT OrderID FROM LastCap)

5000 orders isn't so many so it will be fast even without indexes.
0
 
LVL 27

Expert Comment

by:CaptainCyril
ID: 39191065
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2)
0
 
LVL 42

Expert Comment

by:pcelba
ID: 39191077
If you don't have unique ID then you have to use some time stamp but you have to ensure timestamp values can do the job, e.g. two orders having same time stamp but just one of them exported the first time will produce incorrect result.

SELECT * FROM Capacity
WHERE TimeStamp > (SELECT MAX(TimeStamp) FROM LastCap)
0
 

Author Closing Comment

by:ClaytonGlass
ID: 39191095
Thanks a lot for very prompt and effective answers! I asked a question about python 2 months ago and am still waiting! Thanks to Captain Cyril, too.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39192322
What makes me think is, you say you compare lastcap and thiscap, two copies of the capcity table before and after update.

But there is an update routine (in oracle?) which does merge oracle data into capacity.dbf, so at that stage it's already known, which records already were in capacity.dbf and which have to be added.

So I'd say the solution to your problem is already solved and you redo this by the comparison. Even if it's not much to do, when this raises at 500 records per 3 hours, you sooner or later will see a slow down, just even making the copies before and after merges will take longer and longer.

What I would question is, if the only difference is added records, because then you'd only need to store the reccount before and after the data merging, and will know how many records are new in the DBF. And as new records always are appended at the end of a dbf file, you'd then know the new records are from oldreccount+1 to EOF.

And that doesn't need two DBFs to compare.

Bye, Olaf.

PS: If this wasn't oracle, but T-SQL and the merging would be done inside SQL Server, I'd have an idea to both merge data and output the records that changed or were added as new orders with the OUTPUT clause of a MERGE Statement (an SQL command VFP does not have, though, and I don't know about oracle).

And there are even better options about logging changes via triggers and then export that changelog table. Transaction log also is one source of such change data, even without any triggers. Again I only know for SQL Server you can make use of DBCC LOG.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

628 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