Home > database >  Consult an essentially inventory list update problem
Consult an essentially inventory list update problem

Time:11-10

With transaction update inventory table topics below which bosses can give code

CodePudding user response:

 ALTER the TRIGGER [dbo] [UpDate_GG] 
ON [dbo]. [they]
FOR UPDATE

If the UPDATE ([number])
The update T1 set T1. [number]=T1. [number] + inserted. [number] from T1, inserted where T1. [number]=inserted. [number]


GG table to be a trigger. Probably is this meaning.

CodePudding user response:

reference 1st floor weixin_41697657 response:
 ALTER the TRIGGER [dbo] [UpDate_GG] 
ON [dbo]. [they]
FOR UPDATE

If the UPDATE ([number])
The update T1 set T1. [number]=T1. [number] + inserted. [number] from T1, inserted where T1. [number]=inserted. [number]


GG table for a trigger. Probably is this meaning.
thank you but this is written in the trigger use transaction how the begin... End the update this

CodePudding user response:

 
- the original from https://blog.csdn.net/laizhixue/article/details/100729016
- open transaction
The begin tran
- error capture mechanism, look good, there are also some, and can be nested,
Begin the try
- statement right
Insert into mattress (Eat, Play, Numb) values (' pork ', 'football', 1)
Error - Numb for int type,
Insert into mattress (Eat, Play, Numb) values (' pork ', 'football', 'ABC')
- statement right
Insert into mattress (Eat, Play, Numb) values (' dog ', 'basketball', 2)
End the try
The begin catch
Select Error_number () as ErrorNumber, -- error code
Error_severity () as ErrorSeverity, -- error severity levels, level is less than 10 try catch catch less than
Error_state () as ErrorState, -- error status code
Error_Procedure () as ErrorProcedure, the name of the stored procedure or trigger - errors,
Error_line () as ErrorLine, the number of rows in the error -
Error_message () as ErrorMessage - the details of the error
If (@ @ trancount> 0) - global variable @ @ trancount, affairs open this value + 1, he is used to determine a open transaction
The rollback tran - due to an error, here to roll back to start, the first statement didn't insert success,
End the catch
If (@ @ trancount> 0)
Commit tran - if successful mattress in the table, there will be three data,

- the table itself is empty table, ID, Numb for int type, the other for nvarchar type
Select * from mattress

CodePudding user response:

The number of the UPDATE T1 SET number=a + B.
The FROM GG B
WHERE a T1. Number=b. number

CodePudding user response:

The begin transaction
Insert into Test (no., quantity)
Select distinct number, 0
The from CG where not the exists (select 1 from the Test where the Test. The number=CG. Number)

Update a set a. number=isnull (a. number, 0) + b. number
From the Test a,
(
Select sum (number) number, serial number from CG
Group by no.
B)
Where a. number=b. number
The delete from CG
Commit the transaction

CodePudding user response:

Directly in a stored procedure, using triggers a lot better now than you, if the client use batch updates, you this trigger is likely to pull the server to die


Begin the try
The begin transaction
Insert into GG ()

Update the inventory set...

Commit the transaction
End the try
The begin catch
If @ @ TRANCOUNT> 0
The rollback transaction
Raiseerror (' valentine's day is coming, 16, 1)
End the catch
  • Related