SQL server 2005 - accessing a table from another database

  • Hello,

    I'm writing a stored proc. in SQL Server 2005. I need to get data from another database in SQL Server 2005 on the same server.

    Do I have to go down the linked server route or what is the syntax to do this?

    SELECT *

    FROM [dbo].[dbname].[dbtable]

    ?

    thanks,

    Paul

  • Linked servers are for databases on other servers.

    FROM <database>.<schema>.<tablename>

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • require 4 parts for linked server, so it should be <server>.<database>.<schema>.<table>

    sp_addlinkedserver 'serverA'

    exec serverA...sp_who2 <= to test that your linked server work.

    -----------------------------
    www.cbtr.net
    .: SQL Backup Admin Tool[/url] :.

  • Don't need link server. Simply give..

    select * from databasename..tablename

  • thanks.....

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply