Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
Delete from Two tables in Single Statement...
Delete from Two tables in Single Statement (without Cascading)
Rate Topic
Display Mode
Topic Options
Author
Message
Mr. Kapsicum
Mr. Kapsicum
Posted Tuesday, February 05, 2013 2:11 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 1:41 AM
Points: 121,
Visits: 84
Table A
------------
ID NAME
1 'A'
2 'B'
3 'C'
TABLE B
------------
ID NAME
1 'A'
2 'B'
3 'C'
4 'D'
5 'E'
SAME ROW
1 'A'
2 'B'
3 'C'
I want to delete these records from both the table in single DELETE statement. and DON'T USE CASCADING.
Need Help..............a bit urgent..........!!!!!
Post #1415651
Eugene Elutin
Eugene Elutin
Posted Tuesday, February 05, 2013 2:31 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 9:48 AM
Points: 2,534,
Visits: 4,351
[b]
I want to delete these records from both the table in single DELETE statement. and DON'T USE CASCADING.
Need Help..............a bit urgent..........!!!!!
It is impossible in SQL.
You can not DELETE or INSERT or UPDATE more than one table in a single statement (exclusion is using OUTPUT clause which allows to insert results of modification operation into separate table).
Actually what is the reason you want to delete from two table in single statement? If it's to maintain data consistency, than just do your deletes in single transaction.
_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
Post #1415655
Mr. Kapsicum
Mr. Kapsicum
Posted Tuesday, February 05, 2013 2:38 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Today @ 1:41 AM
Points: 121,
Visits: 84
thanks sscrazy.........!!!!
it's a quick response.
There is nothing about consistency......... its just a question that someone asked me to do so..... he says its possible....!!!!
Trigger,OUTPUT, cascading are possible solution but i dont have to use none of them,,,,,,,!!! i guess MySQL has this capability......
I guess,,,,, it can be done.....!!!!
Post #1415661
Eugene Elutin
Eugene Elutin
Posted Tuesday, February 05, 2013 2:45 AM
SSCrazy
Group: General Forum Members
Last Login: Today @ 9:48 AM
Points: 2,534,
Visits: 4,351
Mr. Kapsicum (2/5/2013)
thanks sscrazy.........!!!!
it's a quick response.
There is nothing about consistency......... its just a question that someone asked me to do so..... he says its possible....!!!!
Trigger,OUTPUT, cascading are possible solution but i dont have to use none of them,,,,,,,!!! i guess MySQL has this capability......
I guess,,,,, it can be done.....!!!!
That is SQL Server server forum...
Yes, you can do it in MySql.
_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)
How to post your question to get the best and quick help
Post #1415669
Grant Fritchey
Grant Fritchey
Posted Tuesday, February 05, 2013 3:53 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 10:37 AM
Points: 13,375,
Visits: 25,158
The only thing you can do is run the two delete statements inside a single transaction. Then, the data gets deleted, effectively, together and at the same time. But the delete statements themselves are two different deletes. As long as they're wrapped inside a transaction though, they'll complete or rollback as a single unit.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #1415698
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.