Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to check if a database is on the server

Author  Topic 

insanepaul
Posting Yak Master

178 Posts

Posted - 2008-12-14 : 13:54:14
I use a linked server to programmatically send data from 1 server to a remote server.

However on occasion the database on the remote server may actually reside on the same server. If this is true then there is no point in opening a linked server.

I've noticed that all the database's have a unique name. So I think all I have to do is search the existing server for the database name.

How would I do this?

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2008-12-14 : 14:00:49
SQL 2000:
IF EXISTS(SELECT 1 FROM master..sysdatabases WHERE name = 'Your database name')
-- Do something

SQL 2005/2008
IF EXISTS(SELECT 1 FROM sys.databases WHERE name = 'Your database name')
-- Do something

--
Gail Shaw
SQL Server MVP
Go to Top of Page

insanepaul
Posting Yak Master

178 Posts

Posted - 2008-12-14 : 15:09:42
quote:
Originally posted by GilaMonster

SQL 2000:
IF EXISTS(SELECT 1 FROM master..sysdatabases WHERE name = 'Your database name')
-- Do something

SQL 2005/2008
IF EXISTS(SELECT 1 FROM sys.databases WHERE name = 'Your database name')
-- Do something

--
Gail Shaw
SQL Server MVP



Thats great thanks
Go to Top of Page
   

- Advertisement -