sql - Trigger when update, insert, delete inventory -
I want to create a trigger to update and insert my inventory table.
When the quantity changes and it is less than 0, then I want to inscoke in my table that the product can be changed, and if the quantity is greater than 0.
My effort does not work at all.
- Create table 'Make product' table [DBO]. [ProductSet] NVarchar (max) Nov, NVarchar (max) No, zero, [imagepath] nerve (max) no, zero [unicaturase] [productive] int identity (1,1) no tap, [product name] nvarchar (maximum) ] Is not float, [classified] it is not, [instock] bit not); Go - Create table 'inventory set' table [DBO]. [Inventory reset] ([inventory ID] int idtt (1,1) no tap, [quantity] is not iit, [product id] is not IT); Go I know this is wrong, but here you can go. : P
Make Trigger [DBO]. [DBO] on [testtrigar] [Inventoryset] After INSERT, set notebook as update; If (SELECT dbo.InventorySet.Quantity) & gt; 0 Then Debo. Insert in the product set (INSTOCK) VALUE (1) dbo.ProductSet (InStock) VALUE (2) END GO I have it now:
- trigger for creating Initier Database [DBO]. [Dbo] on [instobotig] [Inventoryset] INSERT launches, as the beginning of the update, negative; @quantity bit select @quantity = dbo.InventorySet.Quantity from dbo.InventorySet if @Quantity> Initially include dbo.ProductSet (InStock) values (1) dbo.ProductSet (InStock) values (INSTOCK) values go (2) END but when I add it I want it to update InStock (as I wrote my trigger) but it is not.
Enter value in inventory (Inventory, Quantity, Product ID) on SET IDENTITY_INSERT inventory (1, 25, 1); Insert Inventoryset (Inventory ID, Quantity, Product ID) values (2, 31, 2); Insert Inventoryset (Inventory ID, Quantity, Product ID) values (3, 2, 3); Insert Inventoryset (Inventory ID, Quantity, Product ID) values (4, 0, 4); Instead, I get this error: Message 515, Level 16, State 2, Process inStockTrigger, Row 309 can not contain value tap in column I 'Product Name', Table 'ModelFirst.SupplementStore.dbo. ProductSet '; Column faucets do not allow INSERT fails This statement has been terminated.
You are inserting after the update. After the fire is inserted, instead of putting or removing fire, you need access to the Insert / Delete tables instead of fire
You need to use. Make a better blog post about this IO
Make Trigger [DBO]. [DBO] on [testtrigar] [Inventoryset] INSTEAD INSERT, update as updated; - Now check that you have inscac quantity that you want and make your magic. If you post your
- table schema, then I
go
Comments
Post a Comment