请问如何删除一个视图里的一行?
SELECT dbo.BoxLabelTable.BoxSN, dbo.ElabelTable.ESN
FROM dbo.BoxLabelTable INNER JOIN
dbo.ElabelTable ON dbo.BoxLabelTable.BoxLabelID = dbo.ElabelTable.BoxLabelID
where dbo.ElabelTable.ESN= 'AAA '
如上面的视图
查找ESN= 'AAA '的记录,使用
delete A
FROM dbo.ElabelTable A INNER JOIN
dbo.BoxLabelTable B ON
A.BoxLabelID = B.BoxLabelID
where esn= 'AAA '
结果只删除了dbo.elabeltable里esn= 'AAA '的记录.但没有删除dbo.boxlabeltable.boxsn这条记录
但为什么在视图设计器里就可以呢?
thanks
------解决方案--------------------两个表有级联或触发器才能实现楼主的效果.
处理方法:
select A.BoxLabelID,esn into #--生成临时表
FROM dbo.ElabelTable A INNER JOIN
dbo.BoxLabelTable B ON
A.BoxLabelID = B.BoxLabelID
where esn= 'AAA '
--执行
delete A--这是定义删除表的定义
FROM dbo.ElabelTable A INNER JOIN
dbo.BoxLabelTable B ON
A.BoxLabelID = B.BoxLabelID
where esn= 'AAA '
delete b
from dbo.BoxLabelTable B inner join # b on A.BoxLabelID = B.BoxLabelID