0

Я хочу создать тригер, который будет обновлять значение одной таблицы в зависимости от того, какие данные мы добавили в другую таблицу, и в результате обновления выполняет или не выполняет действие.

create trigger Arch_1Unit
on Sales After Insert as 

Update Product 
set Product.Count_ = Product.Count_ - inserted.Count_ 
where Product.Name = Name

if (Select Count_ from Product where inserted.Name = Product.Name) <= 0 

begin
INSERT INTO Archive select Product.Name, Product.Type, Count_, Prime_Cost, Manufacturer, Product.Saleprice from Product where Product.Name = inserted.Name

Update Product 
set Count_ = Count_ + 50
where Product.Name = inserted.Name

end;

Но я столкнулся с ошибкой:

The multi-part identifier "inserted.Count_" could not be bound.

Не могу понять, почему я не могу использовать данные из виртуальной таблицы inserted.

2
  • 1
    inserted - это таблица, вставляться могут несколько строк одновременно и в триггере будет тоже несколько строк
    – Konst
    18 июл 2019 в 11:07
  • Спасибо за подсказку.
    – Arkenstone
    18 июл 2019 в 11:13

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.