Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ad hoc default value
Message
 
 
À
27/02/2002 08:58:10
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Conception bases de données
Divers
Thread ID:
00621581
Message ID:
00626802
Vues:
34
Hello, Mike.

> ... it is easy enough to kill the transaction if multiple rows are inserted by placing the following snippet at the top of your trigger.
>
>
>DECLARE @rowcnt int
>SET @rowcnt = @@ROWCOUNT
>IF @rowcnt > 1
> BEGIN
> RAISERROR ('your error message'), 16, 1
> ROLLBACK TRANSACTION
> END
>
>
>

I incorporated this snippet in the trigger

>Also, I think you've left yourself open to duplication if concurrency is high enough.
>
>
>set @nNext=(select top 1 pksm+1 from cpu where pksm is not null
>and pksm+1 not in (select pksm from cpu where pksm is not null)
>order by 1)
>
>
>this section does not hold any locks. Since it is a read operation, SQL Server will only use Shared locks. there is nothing that prevents two connections from entering the trigger and getting the same number. the possibility of it happening depends on the number of concurrent inserts into the table.
>

Hold on for a moment, please.
I always thought that for the same table only _one_ trigger can fire at the same time, that’s why i did not even consider turning any locks. Was i wrong?
Best wishes :)
Kamil.
A moment of silence is our cosmic reset button.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform