• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 671
  • Last Modified:

Querying sys.objects

Is there a way to query another databases sys.objects collection without creating a linked server? For example, I need to check whether a table exists in another database before doing something. Normally I would query sys.objects to get this but I don't want to create a linked server for this case to get it. Any ideas?
0
brianwells05
Asked:
brianwells05
2 Solutions
 
dan_nealCommented:
If its on a different server you can try using the OPENDATASOURCE command.  See Books Online for syntax.
0
 
ThorSG1Commented:
I have not used this but Dan is correct.  I took this example from books online and modified it to hit sys.objects.  You just need to put in your remote server name

SELECT *
FROM OPENDATASOURCE('SQLNCLI',
    'Data Source=RemoteServerName;Integrated Security=SSPI')
    .master.sys.objects

Open in new window

0
 
brianwells05Author Commented:
I was looking for something simple like this: "select * from [Database].sys.tables"
I should have mentioned that I was looking on the same server...but that's a very useful technique for remote servers....thanks for the input.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now