如何用一条语句同时删除2张表的数据

[复制链接]
查看11 | 回复4 | 2008-2-24 13:46:08 | 显示全部楼层 |阅读模式
delete from table1,table2 where 1=1
回复

使用道具 举报

千问 | 2008-2-24 13:46:08 | 显示全部楼层
楼主为什么要用一条啊?是为了实现要么同时删除,要么都不删除么?如果是的话,可以这样写if exists (select * from table1 where a='1') and exists (select * from table2 where a='1')beginbegin transactiondelete from table1if @@error0beginrollback transactionenddelete from table2if @@error0beginrollback transactionendcommit transactionend
回复

使用道具 举报

千问 | 2008-2-24 13:46:08 | 显示全部楼层
delete from table1;delete from table2 ;
回复

使用道具 举报

千问 | 2008-2-24 13:46:08 | 显示全部楼层
delete from table1 where a=1delete from table2 where a=1只能分开写,想偷下懒是不行的哦
回复

使用道具 举报

千问 | 2008-2-24 13:46:08 | 显示全部楼层
要想用 一条语句学就用触发器 做不清楚..干嘛不用两条语句..
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行