我有一个正在生产的数据库,已经被引入进行更改。一切顺利,除了我无法执行DELETE。我知道这是因为连接和错误的引用。完整性等,但我无法真正改变。
下面的select语句执行没有问题,并显示在gridview中:
SELECT
[Stock Inventory].MaterialNumber,
[Stock Inventory].[Optimum Stock] AS Optimum_Stock,
customerservice.Part,
customerservice.SamplesRequired,
customerservice.Frequency,
customerservice.Country
FROM
[Stock Inventory]
INNER JOIN customerservice
ON [Stock Inventory].MaterialNumber = customerservice.Part
我正在寻找使用已生成表一部分的删除链接
如果我没有提供足够的信息,请告诉我
最佳答案
由于您提到需要从两个表中删除,因此可以执行以下操作:
begin transaction
declare @deleted table (MaterialNumber int) --whatever data type you need
DELETE s
output deleted.MaterialNumber into @deleted
from [Stock Inventory] as s
INNER JOIN customerservice as c
ON s.MaterialNumber = c.Part
DELETE c
from customerservice as c
join @deleted d
on d.MaterialNumber = c.Part
commit transaction