Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How Transaction fails?
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01537235
Message ID:
01537238
Views:
35
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform