Given a SQL script:
- Start a transaction. It is initiated from server X
- Do a select into from a query involving table A into table B (= new table)
- Select table A into table C (= new table)
- Commit.
No errors happen. This is NOT a distributed transaction yet, since everything happens on 1 server.
Now let’s say 3. becomes:
- Select table A into table C, but table C is on a different server (I have to do this via
EXECUTE('SELECT * INTO ...') AT [remoteserver]because 3 prefix syntax is allowed in the FROM clause but not in the INTO clause)
Now SQL Server tells me this statement (3) generates a conflict with another statement in the (now distributed) transaction.
To show you where the error is coming from and to prove that distributed transactions do actually work on my setup I now comment out step 2) !
Now the whole thing works. So step 2) makes the problem occur. But step 2) basically only does a joined select on table A and some other tables to generate table B and nothing else.
Why cannot step 3) execute without problems in that case (in the distributed transaction version), but the same non-distributed transaction version works flawlessly? And what conflict can there possibly be?
OK guys. Found out the problem, and it is interesting. It was something else. I did not mention that I also created table A, because I thought it had nothing to do with the problem, so:
Replace step 2) with
Now the non distributed version works, the distributed version does not (step 3 that is).
Replace step 2) with
Now both versions work fine.
But I don’t care really because the whole thing also works when I create the table with a primary key somewhere before the transaction. It is just that creating the primary key with the create table statement in the transaction causes 3) distributed version to not work.
If someone knows why please write it here 🙂