Home All Groups Group Topic Archive Search About
Author
23 Mar 2006 10:14 PM
MC
Can someone help me for a SQL query to delete all the transactions from 2
SQL table?
Here is what I want to do.
"Go thru all the transactions in both table A and B
If table A has a record, delete this record first, then delete the same
record info from B

If table A has no record reference, continue and delete the record in B"

and so on.
Thanks

Author
23 Mar 2006 11:23 PM
Erland Sommarskog
MC (webmas***@ozoptics.com) writes:
> Can someone help me for a SQL query to delete all the transactions from 2
> SQL table?
> Here is what I want to do.
> "Go thru all the transactions in both table A and B
> If table A has a record, delete this record first, then delete the same
> record info from B
>
> If table A has no record reference, continue and delete the record in B"

DELETE B
DELETE A

And most of all, don't delete row by row, delete all in one statement.




--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
24 Mar 2006 2:06 PM
MC
My mistake,
Actually, I wanted to delete the records in both Table A and B, before Oct
4, 2004
MC

Show quote
"Erland Sommarskog" <esq***@sommarskog.se> wrote in message
news:Xns979040CD7705Yazorman@127.0.0.1...
> MC (webmas***@ozoptics.com) writes:
> > Can someone help me for a SQL query to delete all the transactions from
2
> > SQL table?
> > Here is what I want to do.
> > "Go thru all the transactions in both table A and B
> > If table A has a record, delete this record first, then delete the same
> > record info from B
> >
> > If table A has no record reference, continue and delete the record in B"
>
> DELETE B
> DELETE A
>
> And most of all, don't delete row by row, delete all in one statement.
>
>
>
>
> --
> Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se
>
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
27 Mar 2006 6:58 PM
JP Bless
DELETE TableA.*, TableA.DateField
FROM TableA WHERE TableA.DateField < 10/4/2004


Show quote
"MC" <webmas***@ozoptics.com> wrote in message
news:OLN%23fw0TGHA.1868@TK2MSFTNGP09.phx.gbl...
> My mistake,
> Actually, I wanted to delete the records in both Table A and B, before Oct
> 4, 2004
> MC
>
> "Erland Sommarskog" <esq***@sommarskog.se> wrote in message
> news:Xns979040CD7705Yazorman@127.0.0.1...
> > MC (webmas***@ozoptics.com) writes:
> > > Can someone help me for a SQL query to delete all the transactions
from
> 2
> > > SQL table?
> > > Here is what I want to do.
> > > "Go thru all the transactions in both table A and B
> > > If table A has a record, delete this record first, then delete the
same
> > > record info from B
> > >
> > > If table A has no record reference, continue and delete the record in
B"
> >
> > DELETE B
> > DELETE A
> >
> > And most of all, don't delete row by row, delete all in one statement.
> >
> >
> >
> >
> > --
> > Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se
> >
> > Books Online for SQL Server 2005 at
> >
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Show quote
> > Books Online for SQL Server 2000 at
> > http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
>
>

AddThis Social Bookmark Button