对于每个删除语句,我想从具有相同条件(where 子句)的多个表中删除数据。
delete from tblA where id in (select x.id from tblX x where name like N'%test%')
delete from tblB where id in (select x.id from tblX x where name like N'%test%')
delete from tblC where id in (select x.id from tblX x where name like N'%test%')
delete from tblD where id in (select x.id from tblX x where name like N'%test%')
有没有办法声明一个存储来自上面 select 语句的 id 的列表?
我试过了:
declare @ids int
set @ids = select x.id from tblX x where name like N'%test%'
但它抱怨说
子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或子查询用作表达式时,这是不允许的。
请指教,谢谢。