Solved

Deleting records from 2 tables vfp

Posted on 2013-05-23
5
458 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
5 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 250 total points
Comment Utility
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
Comment Utility
SELECT * FROM table1 WHERE id NOT IN (SELECT id FROM table2)
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
HOW TO: Connect to the VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere (HTML5 Web) Host Client 6.5, and perform a simple configuration task of adding a new VMFS 6 datastore.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now