473,508 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to check does some database exist ?

hello

What query shoul I send to SQL serwer ( in transact SQL language ) to check
does some database exist on serwer ? It similar to problem "does some table
exist in database" - resolve to it is query:

use db_silnik
IF EXISTS (SELECT * FROM prad)
PRINT 'table exist'

but what is the query to check does some database exist on serwer ?

best regards
Adam

Aug 15 '05 #1
2 17881
There are (at least) a couple of ways:

select db_id('SomeDatabase') -- if NULL, the database doesn't exist

if not exists (
select *
from master.dbo.sysdatabases
where name = 'SomeDatabase')
print 'Database does not exist'
Note that these queries won't tell you if the database is accessible or
not - it may be offline or loading, or your login may not have been
granted access to it; see DATABASEPROPERTYEX() and HAS_DBACCESS() in
Books Online.

Simon

Aug 15 '05 #2
adam (er******@wp.pl) writes:
What query shoul I send to SQL serwer ( in transact SQL language ) to
check does some database exist on serwer ?
IF db_name(@db) IS NOT NULL
PRINT 'Database exists'
It similar to problem "does some table exist in database" - resolve to
it is query:

use db_silnik
IF EXISTS (SELECT * FROM prad)
PRINT 'table exist'


Ehum, this query will fail if the table does not exist. This query checks
whether there is any data in the table.

To check whether a table exists, use:

IF object_id(@tbl, 'U') IS NOT NULL
PRINT 'Table exists'

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for
SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Aug 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1335
by: Sal | last post by:
I am new to ASP.Net and I am trying to to make simple SQLConnection to the pubs database that comes with SQLServer2000. I have attempted many things to try and resolve it. I tried adding ASPNET...
2
5901
by: mal hit | last post by:
We developed an ASP.NET application on Windows 2000/SQL Server 2000/IIS 5.0. Recently, we moved the SQL Server 2000 database to Windows 2003. Now, we are unable to connect to the database (on...
2
3270
by: george r smith | last post by:
Gentlemen, I know that this problem has happened before and I searched and tried all solutions but problem is not solved. I install asp.net community starter kit with some help from this...
4
1342
by: Graham Hurst | last post by:
Hi all, A very frustrating problems - searches on the net haven't found much of relevance. I have two SQL databases - a TEST and a LIVE. My asp.net application, with C# codebehind, uses the...
5
2781
by: Ben | last post by:
Hi I am updating a project from Access to run on our SQL Server DB. Currently I am struggling to connect to the database. I have this code which is throwing this error: SQL Server does not...
10
25102
by: steingold | last post by:
Hi all, I wrote an application that takes snapshots using the snapshot monitor API (db2gGetSnapshot and db2GetSnapshotSize), every now and then these methods fail and I get SQL1024N error (A...
3
3230
by: sammyloo | last post by:
Hi all, I'm experiencing a problem using ASP.NET web services to access a different server with SQL Server 2000 database. And I get the error of the following Exception Details:...
11
7842
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
3
2153
by: bharathi228 | last post by:
how to check if database exist or not in sqlserver through asp.net code. if not exists i will give msgbox to user otherwise i will allow the user to create reports pls any one give me...
0
7124
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.