2

if (1st table exists) then select date from 1st table and call a (procedure) how to do this?

2
  • 1
    swl (in your title) !?!?!? What/who is that ? Commented Sep 11, 2013 at 11:43
  • Which DBMS are you using? Postgres? Oracle? Commented Sep 11, 2013 at 12:34

2 Answers 2

7

I like this method for checking an objects existence.

IF Object_ID('dbo.your_table', 'U') IS NOT NULL
  BEGIN
    /* Table exists */
  END
ELSE
  BEGIN
    /* Table does not exist */
  END

The Object_ID() function returns the... object_id(!) of the specified object. If the object doesn't exist then it returns NULL. The second [optional] parameter being passed here is a U which is the object type (U=User table, V=View, P=Procedure... see type column here for more info here).

Basically this is a short hand (lazy? ahem) method of checking for an objects existence

Sign up to request clarification or add additional context in comments.

1 Comment

assumed this was for SQL Server... Apologies if not!
1

Verify if the table exists before proceeding;

IF  NOT EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N'[dbo].[YourTable]') AND type in (N'U'))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.