2

我有一个生产中的数据库,并已被引入进行更改。一切顺利,除了我无法执行 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

我正在寻找使用生成表的一部分的删除链接如果我没有提供足够的信息,请告诉我

4

1 回答 1

0

由于您提到需要从两个表中删除,您可以执行以下操作:

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
于 2013-07-23T17:59:33.187 回答