Ibrahim Sefa Tuna
Ibrahim Sefa Tuna

Reputation: 11

Shared Table between different databases (SQL Server)

Database1

Database2

I have a table which is include product details and I use them for 2 seperated databases .Can i make Z_Table as a shared table?

Because when i want to update Z_Table i have to do that for both DB's.

**i know that i can deal with it with serverside coding (queries).But if i can do that on Sql server that would be nice.

Upvotes: 1

Views: 3216

Answers (1)

Sean Lange
Sean Lange

Reputation: 33581

You can't actually have a shared table. But you can use synonyms. That means you could have Z_Table in Database1 and a synonym in Database2 which points to that table in Database1.

In Database2 you could create it like this.

CREATE SYNONYM Z_Table FOR Database1.Z_Table

Then in queries from Database2 you just reference it by the name. You can treat it just like any other table.

You can read more about synonyms here. https://learn.microsoft.com/en-us/sql/relational-databases/synonyms/synonyms-database-engine

Upvotes: 6

Related Questions