You'd rather put the table creation DDL script instead of the screen.
Suppose the tables are created as follows:
create table Ведомость_материалов ( ID int primary key, Материал nvarchar(max), Количество_на_складе int ) create table Журнал_прихода ( ID int primary key, Наименование_детали nvarchar(max), Количество int )
I assume that the Материал column in one table will have the same values as the Наименование_детали column in another.
Then the trigger can be:
create trigger Заявка_ЖурналВедомость on Журнал_прихода for insert AS if @@ROWCOUNT = 1 begin update Ведомость_материалов set Количество_на_складе = Количество_на_складе + (select Количество from inserted) where Материал = (select Наименование_детали from inserted) end
This trigger is triggered when inserting into one table, updating data in another table.
Fill the table of Material Sheets with initial values:
insert Ведомость_материалов values (1, N'болт', 0); insert Ведомость_материалов values (2, N'шуруп', 0);
Now, when inserting entries into the Incoming Log:
insert Журнал_прихода values (1, N'болт', 100); insert Журнал_прихода values (2, N'болт', 200); insert Журнал_прихода values (3, N'шуруп', 1000); insert Журнал_прихода values (4, N'шуруп', 3000);
trigger will trigger and update the amount of material in stock.
select * from Ведомость_материалов; ID | Материал | Количество_на_складе 1 | болт | 300 2 | шуруп | 4000
Look at this material about triggers, there just examples are similar to what you are doing.