Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would transaction work across multiple DB in the same SQL server? If so, is this a Distributed transaction?

Would transaction work across multiple DB in the same SQL server? If so, is this a Distributed transaction? or would basic BEGIN TRANSACTION work?

like image 210
Henry Avatar asked Jul 04 '13 23:07

Henry


People also ask

How do you achieve transactions when dealing with two different databases?

If your data is distributed across multiple databases, you may wish to update one database while reading from one or more other databases. This type of access can be performed within a single unit of work (transaction). This type of database access is called multisite update or two-phase commit.

How does distributed transaction work in SQL Server?

A distributed transaction spans two or more databases. As the transaction manager, DTC coordinates the transaction between SQL Server instances, and other data sources. Each instance of the SQL Server database engine can operate as a resource manager.

Can you query across databases in SQL Server?

Starting with SQL Server 2014 (12. x), memory-optimized tables do not support cross-database transactions. You cannot access another database from the same transaction or the same query that also accesses a memory-optimized table.

How do distributed transactions work?

A distributed transaction is a set of operations on data that is performed across two or more data repositories (especially databases). It is typically coordinated across separate nodes connected by a network, but may also span multiple databases on a single server.


2 Answers

A transaction across multiple DBs in the same instance is a local transaction. BEGIN TRANSACTION will work just fine.

like image 190
Vlad G. Avatar answered Oct 14 '22 05:10

Vlad G.


Just tested it. BEGIN TRANSACTION works as expected across two databases on the same server.

like image 9
John Tseng Avatar answered Oct 14 '22 05:10

John Tseng