Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How Transaction fails?
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01537235
Message ID:
01537238
Vues:
32
>Hi,
>
>I have the following constraint set on the foreign key field of the child table:
>
>
>ALTER TABLE [dbo].[child_tbl]  WITH CHECK ADD  CONSTRAINT [FK_child_tbl_employee] FOREIGN KEY([employee])
>REFERENCES [dbo].[parent_tbl] ([employee])
>
>
>Why do you think the following code in the SSMS gets error of constraint conflict?
>
>
>use [MyDatabase]
>go 
>begin transaction
>update parent_tbl set employee = 'TEST34' where employee = 'TEST1'
>go
>update child_tbl set employee = 'TEST34' where employee = 'TEST1'
>go
>commit 
>
>
>TIA

GO statement in SSMS ends the batch (it's a bacth separator). You started transaction but you never ended it in the first batch, so I assume it rollbacked by default. You need to commit it before GO, then the second statement will work. But also, for a single statement you don't need a transaction at all.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform