Results 1 to 9 of 9

Thread: Want a VIEW of remote table to appear in my DB

  1. #1

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Want a VIEW of remote table to appear in my DB

    How can I take a table in a database on server B and make a VIEW of it in my database on server A?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  2. #2
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Want a VIEW of remote table to appear in my DB

    Quote Originally Posted by szlamany
    How can I take a table in a database on server B and make a VIEW of it in my database on server A?
    First of all you must add server B as a linked server on server A. You can do it with sp_addlinkedserver or in EM. It's easier to do it in EM, since you have to specify a security context for the linked server.

    Then you can simply create a view by specifying the four part name of the table on server B. So on server a you execute:
    Code:
    CREATE VIEW [VIEW_NAME]
    AS
    SELECT * FROM SERVERB.DB_NAME.dbo.TABLE_NAME
    Read about distributed partitioned views on BOL. You can actually create an updatable view that consists of tables from multiple servers using UNION ALL and by specifying a unique constraint for the ket columns on the different tables. When you update/delete/add records in the view, SQL Server will yse the constraint to determine on what server the record should be added/deleted/modified.

  3. #3

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Want a VIEW of remote table to appear in my DB

    Thanks a real lot...

    I'm trying to map to a server that the office phone system here uses for tracking calls. The customer wants me to report on the data, but I'm afraid to put any views or sprocs into this database...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Want a VIEW of remote table to appear in my DB

    Thanks again - I tried to rep you, but apparently I must spread some around first...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  5. #5
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Want a VIEW of remote table to appear in my DB

    Quote Originally Posted by szlamany
    Thanks a real lot...

    I'm trying to map to a server that the office phone system here uses for tracking calls. The customer wants me to report on the data, but I'm afraid to put any views or sprocs into this database...
    Are you performing any joins between tables on the two servers?

  6. #6

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Want a VIEW of remote table to appear in my DB

    Quick question - this is working great for me - I can attach.

    But the IT director is getting an error in QA.

    Login Failed for user 'NTAUTHORITY\ANONYMOUS LOGON'

    Any clue?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  7. #7

    Thread Starter
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Want a VIEW of remote table to appear in my DB

    Quote Originally Posted by kaffenils
    Are you performing any joins between tables on the two servers?
    No just straight SELECT's within STORED PROCEDURES - probably with NOLOCK hints to be easy and quick...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Want a VIEW of remote table to appear in my DB

    Quote Originally Posted by szlamany
    Quick question - this is working great for me - I can attach.

    But the IT director is getting an error in QA.

    Login Failed for user 'NTAUTHORITY\ANONYMOUS LOGON'

    Any clue?
    You must create a user on server a with access to the tables you are selecting from. Then you must specify this user name and password for all connections through the linked server.

  9. #9
    Fanatic Member kaffenils's Avatar
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    946

    Re: Want a VIEW of remote table to appear in my DB

    Quote Originally Posted by szlamany
    No just straight SELECT's within STORED PROCEDURES - probably with NOLOCK hints to be easy and quick...
    Ok, I though I should mention, if you had joined data from tables on the different servers, that there is a join hint that allows you to specify which server that should execute the join.
    You can read about it here

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width