Search code examples
sql-serverodbclinked-server

How to set default catalog with linked server in Mssql


Formerly, I had two databases in one physical server. ('People' and 'Work' Database)
So I used the below query when 'People' database information need at 'Work' database.

select * from People.dbo.information

But, It occurred to me something that one physical databases have to be seperatored with two physical server.
Therefore I made linked server connection at 'People' database server for refering Information at 'Work' database same as before name and Then I seted dafualt catalog the 'People' in linked server.

Although I already seted default catalog, I have to enter database's name and can't skip the name.

Phycal Databases was seperatored but I want to use previous query using linked server.

Example) If i made linked server as called 'Peoplo', I have to use below query.

select * from People.People.dbo.information
--select * from [linked name].[db name].[dbo].[table Name]

I want to use below query.

select * from People.dbo.information
    --select * from [linked name].[dbo].[table Name]
    --Then, linked name is seted with default catalog as 'People'

Solution

  • If you have set the "default database" for the login on the linked server, you can use this (2 dots, skipping default catalog)

    select * from People..dbo.information
    

    Note that however you do it, linked servers can have performance issues when joining between servers.

    Also note, the data has no referential integrity at all. The databases will not be synchromised or coherent in case of any downtime or restores etc