Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Trigger - Insert, Update and Delete
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Trigger - Insert, Update and Delete
Miscellaneous
Thread ID:
01188861
Message ID:
01188861
Views:
78
Hi everbody.

I have two tables. Table A has a field called SumQtd and Table B has a field Qtd.

Table A has one record and table B has none, one or more records. The sum of B.Qtd must be stored in A.SumQtd.

I was wondering how to create a Trigger (or other way, no matter here) to do this job for me.

It is so simple if I were using VFP, but I'm starting with SQL and I have no idea how to do this.

Every change at Table B should fires something like this "Select Sum(Qtd) From TableB Where MyId = Inserted.MyId". and then: Update TableA Set SumQtd = 'ThatNumber' Where MyId = InsertedMyId. It should be soooo simple, shouldn't it?

So, I need to calculate it every time a record is inserted, updated or deleted from Table B, so, I wonder I will have to use Inserted and Deleted temp tables, don't I?

Any help is appreciate!

Thanks in advanced!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Rodolfo Duarte
Next
Reply
Map
View

Click here to load this message in the networking platform