Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Trigger - Insert, Update and Delete
Message
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Trigger - Insert, Update and Delete
Divers
Thread ID:
01188861
Message ID:
01188861
Vues:
79
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform