Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Triggers
Message
De
25/02/2009 09:21:21
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01383955
Message ID:
01384030
Vues:
27
Bob, I plan to have the business logic be the primary enforcer of this rule, but I also wanted to enforce it at the database level. So would the best way to "fail" the update be to make the trigger throw an exception?

>Hi Mike,
>
>The trigger would be a good solution as you will know the database will never have the situation (sum of percentage values greater than 1 for a given parentID) regardless of how values are inserted or updated in the database. You will just need to have the proper error handling mechanisms in place to report such an event gracefully in your user interface(s).
>
>I have a similar situation in one of my applications, but I use my business object rule to handle this as it has the reporting mechanisms built into my user interface. However, since I do not have a trigger defined in the database, I could insert or update rows directly in the database directly using T-SQL without any error. This is not a problem for me as this is not likely to happen, however, having the insert and update triggers for this wouldn't hurt and could only help.
>
>HTH
>
>Bob
>
>
>>I have a situation where I have a table with this structure:
>>
>>ID (PK)
>>ParentID (FK)
>>PercentOwnership - Decimal (2,2)
>>
>>I want to check when an item is inserted or updated in this table that the sum of all PercentOwnership fields with the same ParentID doesn't go over 1. I'm assuming I want to use a trigger here and wanted to make sure I was going down the right path (I'm a newbie with triggers). Is this right? Or is there a better way to do this?
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform