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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 If a table exists

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-04-01 : 08:49:03
Matthew writes "I am creating a guest book service. I would like to know if a database exists if I use a code that retrives data from a querystring. So, If I type in for the site:
http://www.mysite.com/guestbook.asp?ID=3
My site will take ID and will see if, for the above example, table 3 exists. The name of the table is table 3. Now, if table three doesn't exists I will write on the screen using Response.Write telling the visitor of the webpage that the guest book does not exist. How can I do this?"

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-04-01 : 08:54:07

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[3]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
RAISERROR('Table does not exist.',16,1)
RETURN 1
END

Is this what you are looking for? You can just pass an error screen to the user based on the raiserror.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -