REPOST - Assistance needed with clearing out Child tables

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Fri, 16 Nov 2001 03:19:21



On further review your suggestion does seem to be the fastest and easiest
way to accomplish what I need to do.

I was wondering if perhaps you could shed further light on your answer.

I have a few questions if you could please spare a few moments.

In my application I have two tables Orders and Details (both of which are
Paradox if it matters) which are linked on secondary indexes by a field
called OrderID. I have tried to code what you suggested below and for the
life of me can't as I always get a error to the effect that I am using a
keyword.

If at all possible can you please shed some light on how this would be done?


> The following query deletes all records in a detail table that have no
> corresponding record in a master table:

> delete detail.*
> from detail left join master
> on detail.key = master.key
> where master.key is null



> > Hey All,
> > I am working on a Paradox database, and need help to remove the records
> from
> > a child database when the master database is emptied or the record is
> > deleted.

> > The records being deleted are cancelled orders, quotes, invoices, and
> other
> > such transactions. I am easily able to get the record from the master
> table
> > but need to know how to get the sometimes multiple records from the
child
> > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by curio » Fri, 16 Nov 2001 15:30:17


try this (assuming pkey - primary key in master and Fkey - foregn key in detail)

 delete from detail where Fkey in
 (select Pkey from master where CONDITION_DESIRED)

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Sat, 17 Nov 2001 03:28:19


thanks for the input, but I was really hoping for some help on the previous
suggestion I was offered as from what I can see its pretty simple but I just
don't understand it. Unfortunately I am a newbie at Delphi database
programming so excuse the stupid questions and comments.


Quote:> try this (assuming pkey - primary key in master and Fkey - foregn key in
detail)

>  delete from detail where Fkey in
>  (select Pkey from master where CONDITION_DESIRED)

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by M.H. Avegaar » Sat, 17 Nov 2001 05:38:59


Sorry, I just changed employer, so I haven't been answering posts lately.
Here is my answer to your previous question:

Put a TQuery on the form, set the DatabaseName property to the same value as
your TTable objects and use the following text in the SQL property:

delete Details.*
from Details left join Orders
on Details.OrderID = Orders.OrderID
where Orders.OrderID is null

and call Query1.ExecSQL in your code.


> On further review your suggestion does seem to be the fastest and easiest
> way to accomplish what I need to do.

> I was wondering if perhaps you could shed further light on your answer.

> I have a few questions if you could please spare a few moments.

> In my application I have two tables Orders and Details (both of which are
> Paradox if it matters) which are linked on secondary indexes by a field
> called OrderID. I have tried to code what you suggested below and for the
> life of me can't as I always get a error to the effect that I am using a
> keyword.

> If at all possible can you please shed some light on how this would be
done?



> > The following query deletes all records in a detail table that have no
> > corresponding record in a master table:

> > delete detail.*
> > from detail left join master
> > on detail.key = master.key
> > where master.key is null



> > > Hey All,
> > > I am working on a Paradox database, and need help to remove the
records
> > from
> > > a child database when the master database is emptied or the record is
> > > deleted.

> > > The records being deleted are cancelled orders, quotes, invoices, and
> > other
> > > such transactions. I am easily able to get the record from the master
> > table
> > > but need to know how to get the sometimes multiple records from the
> child
> > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Sat, 17 Nov 2001 10:50:41


Thanks for the updated info, I will let you know how I make out.


> Sorry, I just changed employer, so I haven't been answering posts lately.
> Here is my answer to your previous question:

> Put a TQuery on the form, set the DatabaseName property to the same value
as
> your TTable objects and use the following text in the SQL property:

> delete Details.*
> from Details left join Orders
> on Details.OrderID = Orders.OrderID
> where Orders.OrderID is null

> and call Query1.ExecSQL in your code.



> > On further review your suggestion does seem to be the fastest and
easiest
> > way to accomplish what I need to do.

> > I was wondering if perhaps you could shed further light on your answer.

> > I have a few questions if you could please spare a few moments.

> > In my application I have two tables Orders and Details (both of which
are
> > Paradox if it matters) which are linked on secondary indexes by a field
> > called OrderID. I have tried to code what you suggested below and for
the
> > life of me can't as I always get a error to the effect that I am using a
> > keyword.

> > If at all possible can you please shed some light on how this would be
> done?



> > > The following query deletes all records in a detail table that have no
> > > corresponding record in a master table:

> > > delete detail.*
> > > from detail left join master
> > > on detail.key = master.key
> > > where master.key is null



> > > > Hey All,
> > > > I am working on a Paradox database, and need help to remove the
> records
> > > from
> > > > a child database when the master database is emptied or the record
is
> > > > deleted.

> > > > The records being deleted are cancelled orders, quotes, invoices,
and
> > > other
> > > > such transactions. I am easily able to get the record from the
master
> > > table
> > > > but need to know how to get the sometimes multiple records from the
> > child
> > > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Sat, 17 Nov 2001 12:10:27


I tried what you suggested and I get a error
"invalid use of keyword.
Token: Details.*
from
LineNumber:1"


> Thanks for the updated info, I will let you know how I make out.



> > Sorry, I just changed employer, so I haven't been answering posts
lately.
> > Here is my answer to your previous question:

> > Put a TQuery on the form, set the DatabaseName property to the same
value
> as
> > your TTable objects and use the following text in the SQL property:

> > delete Details.*
> > from Details left join Orders
> > on Details.OrderID = Orders.OrderID
> > where Orders.OrderID is null

> > and call Query1.ExecSQL in your code.



> > > On further review your suggestion does seem to be the fastest and
> easiest
> > > way to accomplish what I need to do.

> > > I was wondering if perhaps you could shed further light on your
answer.

> > > I have a few questions if you could please spare a few moments.

> > > In my application I have two tables Orders and Details (both of which
> are
> > > Paradox if it matters) which are linked on secondary indexes by a
field
> > > called OrderID. I have tried to code what you suggested below and for
> the
> > > life of me can't as I always get a error to the effect that I am using
a
> > > keyword.

> > > If at all possible can you please shed some light on how this would be
> > done?



> > > > The following query deletes all records in a detail table that have
no
> > > > corresponding record in a master table:

> > > > delete detail.*
> > > > from detail left join master
> > > > on detail.key = master.key
> > > > where master.key is null



> > > > > Hey All,
> > > > > I am working on a Paradox database, and need help to remove the
> > records
> > > > from
> > > > > a child database when the master database is emptied or the record
> is
> > > > > deleted.

> > > > > The records being deleted are cancelled orders, quotes, invoices,
> and
> > > > other
> > > > > such transactions. I am easily able to get the record from the
> master
> > > > table
> > > > > but need to know how to get the sometimes multiple records from
the
> > > child
> > > > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by M.H. Avegaar » Sun, 18 Nov 2001 04:25:50


What are the exact names of your tables and fields ?

It could be that you have to change it to something like:

delete D.*
from "Details.db" D left join "Orders.db" O
on D."OrderID" = O."OrderID"
where O."OrderID" is null


> I tried what you suggested and I get a error
> "invalid use of keyword.
> Token: Details.*
> from
> LineNumber:1"



> > Thanks for the updated info, I will let you know how I make out.



> > > Sorry, I just changed employer, so I haven't been answering posts
> lately.
> > > Here is my answer to your previous question:

> > > Put a TQuery on the form, set the DatabaseName property to the same
> value
> > as
> > > your TTable objects and use the following text in the SQL property:

> > > delete Details.*
> > > from Details left join Orders
> > > on Details.OrderID = Orders.OrderID
> > > where Orders.OrderID is null

> > > and call Query1.ExecSQL in your code.



> > > > On further review your suggestion does seem to be the fastest and
> > easiest
> > > > way to accomplish what I need to do.

> > > > I was wondering if perhaps you could shed further light on your
> answer.

> > > > I have a few questions if you could please spare a few moments.

> > > > In my application I have two tables Orders and Details (both of
which
> > are
> > > > Paradox if it matters) which are linked on secondary indexes by a
> field
> > > > called OrderID. I have tried to code what you suggested below and
for
> > the
> > > > life of me can't as I always get a error to the effect that I am
using
> a
> > > > keyword.

> > > > If at all possible can you please shed some light on how this would
be
> > > done?



> > > > > The following query deletes all records in a detail table that
have
> no
> > > > > corresponding record in a master table:

> > > > > delete detail.*
> > > > > from detail left join master
> > > > > on detail.key = master.key
> > > > > where master.key is null



> > > > > > Hey All,
> > > > > > I am working on a Paradox database, and need help to remove the
> > > records
> > > > > from
> > > > > > a child database when the master database is emptied or the
record
> > is
> > > > > > deleted.

> > > > > > The records being deleted are cancelled orders, quotes,
invoices,
> > and
> > > > > other
> > > > > > such transactions. I am easily able to get the record from the
> > master
> > > > > table
> > > > > > but need to know how to get the sometimes multiple records from
> the
> > > > child
> > > > > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Sun, 18 Nov 2001 06:03:45


Thanks for the input. The exact names of the tables are details and orders
(both are Paradox tables). The link between the two is called OrderID, in
the Orders table OrderID is the primary and on the Details table OrderID is
a secondary index.


> What are the exact names of your tables and fields ?

> It could be that you have to change it to something like:

> delete D.*
> from "Details.db" D left join "Orders.db" O
> on D."OrderID" = O."OrderID"
> where O."OrderID" is null



> > I tried what you suggested and I get a error
> > "invalid use of keyword.
> > Token: Details.*
> > from
> > LineNumber:1"



> > > Thanks for the updated info, I will let you know how I make out.



> > > > Sorry, I just changed employer, so I haven't been answering posts
> > lately.
> > > > Here is my answer to your previous question:

> > > > Put a TQuery on the form, set the DatabaseName property to the same
> > value
> > > as
> > > > your TTable objects and use the following text in the SQL property:

> > > > delete Details.*
> > > > from Details left join Orders
> > > > on Details.OrderID = Orders.OrderID
> > > > where Orders.OrderID is null

> > > > and call Query1.ExecSQL in your code.



> > > > > On further review your suggestion does seem to be the fastest and
> > > easiest
> > > > > way to accomplish what I need to do.

> > > > > I was wondering if perhaps you could shed further light on your
> > answer.

> > > > > I have a few questions if you could please spare a few moments.

> > > > > In my application I have two tables Orders and Details (both of
> which
> > > are
> > > > > Paradox if it matters) which are linked on secondary indexes by a
> > field
> > > > > called OrderID. I have tried to code what you suggested below and
> for
> > > the
> > > > > life of me can't as I always get a error to the effect that I am
> using
> > a
> > > > > keyword.

> > > > > If at all possible can you please shed some light on how this
would
> be
> > > > done?



> > > > > > The following query deletes all records in a detail table that
> have
> > no
> > > > > > corresponding record in a master table:

> > > > > > delete detail.*
> > > > > > from detail left join master
> > > > > > on detail.key = master.key
> > > > > > where master.key is null



> > > > > > > Hey All,
> > > > > > > I am working on a Paradox database, and need help to remove
the
> > > > records
> > > > > > from
> > > > > > > a child database when the master database is emptied or the
> record
> > > is
> > > > > > > deleted.

> > > > > > > The records being deleted are cancelled orders, quotes,
> invoices,
> > > and
> > > > > > other
> > > > > > > such transactions. I am easily able to get the record from the
> > > master
> > > > > > table
> > > > > > > but need to know how to get the sometimes multiple records
from
> > the
> > > > > child
> > > > > > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Sun, 18 Nov 2001 06:05:59


Unfortunately that also gives the same error


> What are the exact names of your tables and fields ?

> It could be that you have to change it to something like:

> delete D.*
> from "Details.db" D left join "Orders.db" O
> on D."OrderID" = O."OrderID"
> where O."OrderID" is null



> > I tried what you suggested and I get a error
> > "invalid use of keyword.
> > Token: Details.*
> > from
> > LineNumber:1"



> > > Thanks for the updated info, I will let you know how I make out.



> > > > Sorry, I just changed employer, so I haven't been answering posts
> > lately.
> > > > Here is my answer to your previous question:

> > > > Put a TQuery on the form, set the DatabaseName property to the same
> > value
> > > as
> > > > your TTable objects and use the following text in the SQL property:

> > > > delete Details.*
> > > > from Details left join Orders
> > > > on Details.OrderID = Orders.OrderID
> > > > where Orders.OrderID is null

> > > > and call Query1.ExecSQL in your code.



> > > > > On further review your suggestion does seem to be the fastest and
> > > easiest
> > > > > way to accomplish what I need to do.

> > > > > I was wondering if perhaps you could shed further light on your
> > answer.

> > > > > I have a few questions if you could please spare a few moments.

> > > > > In my application I have two tables Orders and Details (both of
> which
> > > are
> > > > > Paradox if it matters) which are linked on secondary indexes by a
> > field
> > > > > called OrderID. I have tried to code what you suggested below and
> for
> > > the
> > > > > life of me can't as I always get a error to the effect that I am
> using
> > a
> > > > > keyword.

> > > > > If at all possible can you please shed some light on how this
would
> be
> > > > done?



> > > > > > The following query deletes all records in a detail table that
> have
> > no
> > > > > > corresponding record in a master table:

> > > > > > delete detail.*
> > > > > > from detail left join master
> > > > > > on detail.key = master.key
> > > > > > where master.key is null



> > > > > > > Hey All,
> > > > > > > I am working on a Paradox database, and need help to remove
the
> > > > records
> > > > > > from
> > > > > > > a child database when the master database is emptied or the
> record
> > > is
> > > > > > > deleted.

> > > > > > > The records being deleted are cancelled orders, quotes,
> invoices,
> > > and
> > > > > > other
> > > > > > > such transactions. I am easily able to get the record from the
> > > master
> > > > > > table
> > > > > > > but need to know how to get the sometimes multiple records
from
> > the
> > > > > child
> > > > > > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Tue, 20 Nov 2001 14:01:34


Does anyone know how to make the provided example work????????????


> Unfortunately that also gives the same error



> > What are the exact names of your tables and fields ?

> > It could be that you have to change it to something like:

> > delete D.*
> > from "Details.db" D left join "Orders.db" O
> > on D."OrderID" = O."OrderID"
> > where O."OrderID" is null



> > > I tried what you suggested and I get a error
> > > "invalid use of keyword.
> > > Token: Details.*
> > > from
> > > LineNumber:1"



> > > > Thanks for the updated info, I will let you know how I make out.



> > > > > Sorry, I just changed employer, so I haven't been answering posts
> > > lately.
> > > > > Here is my answer to your previous question:

> > > > > Put a TQuery on the form, set the DatabaseName property to the
same
> > > value
> > > > as
> > > > > your TTable objects and use the following text in the SQL
property:

> > > > > delete Details.*
> > > > > from Details left join Orders
> > > > > on Details.OrderID = Orders.OrderID
> > > > > where Orders.OrderID is null

> > > > > and call Query1.ExecSQL in your code.



> > > > > > On further review your suggestion does seem to be the fastest
and
> > > > easiest
> > > > > > way to accomplish what I need to do.

> > > > > > I was wondering if perhaps you could shed further light on your
> > > answer.

> > > > > > I have a few questions if you could please spare a few moments.

> > > > > > In my application I have two tables Orders and Details (both of
> > which
> > > > are
> > > > > > Paradox if it matters) which are linked on secondary indexes by
a
> > > field
> > > > > > called OrderID. I have tried to code what you suggested below
and
> > for
> > > > the
> > > > > > life of me can't as I always get a error to the effect that I am
> > using
> > > a
> > > > > > keyword.

> > > > > > If at all possible can you please shed some light on how this
> would
> > be
> > > > > done?



> > > > > > > The following query deletes all records in a detail table that
> > have
> > > no
> > > > > > > corresponding record in a master table:

> > > > > > > delete detail.*
> > > > > > > from detail left join master
> > > > > > > on detail.key = master.key
> > > > > > > where master.key is null



> > > > > > > > Hey All,
> > > > > > > > I am working on a Paradox database, and need help to remove
> the
> > > > > records
> > > > > > > from
> > > > > > > > a child database when the master database is emptied or the
> > record
> > > > is
> > > > > > > > deleted.

> > > > > > > > The records being deleted are cancelled orders, quotes,
> > invoices,
> > > > and
> > > > > > > other
> > > > > > > > such transactions. I am easily able to get the record from
the
> > > > master
> > > > > > > table
> > > > > > > > but need to know how to get the sometimes multiple records
> from
> > > the
> > > > > > child
> > > > > > > > database. any ideas?

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Sundial Service » Tue, 20 Nov 2001 14:29:17


Here is one way to do it.

Let us assume that you are using Paradox tables.  So, setting up
"cascading deletes" in your SQL server is not a possibility.

Let's say one TTable is called Invoice and the second is InvoiceLines.

The second TTable uses "SetRange" to limit itself only to the
appropriate range of records; those belonging to the current Invoice.

And what you do, when you get an OnDelete request, is to simply loop
through the LineItems table, deleting records:

        with tLineItems do begin
          disablecontrols;
          try
            first;
            while not EOF do Delete;
          finally
            enablecontrols;
          end;
        end;

If you do have an SQL server, then the easiest way to do this job is to
set up a referential integrity rule that orders the server to delete
child records, directly on the server.


> Does anyone know how to make the provided example work????????????

----------------------------------------------------------------
Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259

Quote:> Fast(!), automatic table-repair with two clicks of the mouse!
> ChimneySweep(R):  Release 4.0 is here!!
> http://www.sundialservices.com/products/chimneysweep

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Tue, 20 Nov 2001 22:57:01


Sundial,
Thanks for your input, however this issue is just making me feel stupid. As
I have said previously I am new to Delphi database programming so my
knowledge is extremely weak (or so I have learned lately).

Where do you code the SetRange information on the second table?

My app has two tables Orders and Details (both are Paradox), the two are
linked by a field called OrderID. The OrderID is the Primary Index on the
Order table and is the on the secondary index of the Details table.


> Here is one way to do it.

> Let us assume that you are using Paradox tables.  So, setting up
> "cascading deletes" in your SQL server is not a possibility.

> Let's say one TTable is called Invoice and the second is InvoiceLines.

> The second TTable uses "SetRange" to limit itself only to the
> appropriate range of records; those belonging to the current Invoice.

> And what you do, when you get an OnDelete request, is to simply loop
> through the LineItems table, deleting records:

> with tLineItems do begin
>   disablecontrols;
>   try
>     first;
>     while not EOF do Delete;
>   finally
>     enablecontrols;
>   end;
> end;

> If you do have an SQL server, then the easiest way to do this job is to
> set up a referential integrity rule that orders the server to delete
> child records, directly on the server.


> > Does anyone know how to make the provided example work????????????

> ----------------------------------------------------------------
> Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259

> > Fast(!), automatic table-repair with two clicks of the mouse!
> > ChimneySweep(R):  Release 4.0 is here!!
> > http://www.sundialservices.com/products/chimneysweep

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Tue, 20 Nov 2001 23:31:48


Sundial,
Also you mentioned a OnDelete when I only see a BeforeDelete or AfterDelete,
where do you find the OnDelete option?


> Here is one way to do it.

> Let us assume that you are using Paradox tables.  So, setting up
> "cascading deletes" in your SQL server is not a possibility.

> Let's say one TTable is called Invoice and the second is InvoiceLines.

> The second TTable uses "SetRange" to limit itself only to the
> appropriate range of records; those belonging to the current Invoice.

> And what you do, when you get an OnDelete request, is to simply loop
> through the LineItems table, deleting records:

> with tLineItems do begin
>   disablecontrols;
>   try
>     first;
>     while not EOF do Delete;
>   finally
>     enablecontrols;
>   end;
> end;

> If you do have an SQL server, then the easiest way to do this job is to
> set up a referential integrity rule that orders the server to delete
> child records, directly on the server.


> > Does anyone know how to make the provided example work????????????

> ----------------------------------------------------------------
> Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259

> > Fast(!), automatic table-repair with two clicks of the mouse!
> > ChimneySweep(R):  Release 4.0 is here!!
> > http://www.sundialservices.com/products/chimneysweep

 
 
 

REPOST - Assistance needed with clearing out Child tables

Post by Daniel Lawrenc » Wed, 21 Nov 2001 15:51:56


Can someone just treat me like a idiot and tell me EXACTLY how to code
this????


> Sundial,
> Also you mentioned a OnDelete when I only see a BeforeDelete or
AfterDelete,
> where do you find the OnDelete option?



> > Here is one way to do it.

> > Let us assume that you are using Paradox tables.  So, setting up
> > "cascading deletes" in your SQL server is not a possibility.

> > Let's say one TTable is called Invoice and the second is InvoiceLines.

> > The second TTable uses "SetRange" to limit itself only to the
> > appropriate range of records; those belonging to the current Invoice.

> > And what you do, when you get an OnDelete request, is to simply loop
> > through the LineItems table, deleting records:

> > with tLineItems do begin
> >   disablecontrols;
> >   try
> >     first;
> >     while not EOF do Delete;
> >   finally
> >     enablecontrols;
> >   end;
> > end;

> > If you do have an SQL server, then the easiest way to do this job is to
> > set up a referential integrity rule that orders the server to delete
> > child records, directly on the server.


> > > Does anyone know how to make the provided example work????????????

> > ----------------------------------------------------------------
> > Sundial Services :: Scottsdale, AZ (USA) :: (480) 946-8259

> > > Fast(!), automatic table-repair with two clicks of the mouse!
> > > ChimneySweep(R):  Release 4.0 is here!!
> > > http://www.sundialservices.com/products/chimneysweep

 
 
 

1. Assistance required on cleaning out child databases

Hey All,
I am working on a Paradox database, and need help to remove the records from
a child database when the master database is emptied or the record is
deleted.

The records being deleted are cancelled orders, quotes, invoices, and other
such transactions. I am easily able to get the record from the master table
but need to know how to get the sometimes multiple records from the child
database. any ideas?

2. Error in assignment (#0) when linking from Access

3. Urgently need assistance, Corrupt table!

4. DC-Washington-103968--CASE Tools-Object Oriented Devel.-ORACLE-SQL-Life Cycle Ap

5. Need Assistance: Constraints in a table

6. Paradox 3.5 - NetWare 5.0 and Unexpected Condition: net IO err

7. Need Assistance: Clustering and Constraints in a table

8. sql for utilization rpt?

9. Need some assistance creating a table in an 8i database

10. How can i clear the MSHFLEXGRID without CLEAR - Como limpar a GRID sem usar CLEAR

11. Assistance needed with creating tables in oracle.

12. Need Assistance: Constraints in a table specific

13. Packing Tables - Need a little assistance