有没有一条语句删除(符合条件的)多表的中记录(如果是用触发器该怎样写呢)

liutingrun 2007-12-12 09:21:38
有没有一条语句删除(符合条件的)多表的中记录(如果是用触发器该怎样写呢)
...全文
63 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
starsong 2007-12-12
  • 打赏
  • 举报
回复
CREATE TRIGGER [TRIGGERFORFORt_test] ON [dbo].[test]
FOR DELETE
AS
delete from table where a.xx= deleted.xx
delete from table where b.xx= deleted.xx
晓风残月0110 2007-12-12
  • 打赏
  • 举报
回复

declare @tb table(id int,t1id int,name varchar(20),work varchar(20))
insert into @tb select 1,1,'张三','教师'
insert into @tb select 2,1,'李四','学生'
insert into @tb select 3,2,'王五','教师'
insert into @tb select 4,3,'赵六',''
insert into @tb select 5,1,'刘七','教师'
declare @ta table(id int,school varchar(20))
insert into @ta select 1,'aa学校'
insert into @ta select 2,'bb学校'
insert into @ta select 3,'cc学校'
select * from @ta
delete from @ta
where id in (select t1id from @tb)
select * from @ta


--
--delete from @ta
--where id in (select t1id from @tb left join 表 .... where id in ....)

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧