From: GW on
hi,

need help,

I have two databases. I have lines in SP running in Database A of which will
check table existence in Database B but it did not find any table even the
said table exists in Database B. Is this possible or did I miss something?

The following failed:-

if exists ( select * from dbo.sysobjects where id =
object_id(N'[DATABASE_B].[dbo].[TABLE_A]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)

drop table [DATABASE_B].[dbo].[TABLE_A]

TQVM.
From: Uri Dimant on
GW
I would check it in the below way
if object_id('dbname.dbo.tblname') is not null

do something











"GW" <GW(a)discussions.microsoft.com> wrote in message
news:7DD62CBF-86E4-4AAA-AE57-222CF775A1DB(a)microsoft.com...
> hi,
>
> need help,
>
> I have two databases. I have lines in SP running in Database A of which
> will
> check table existence in Database B but it did not find any table even the
> said table exists in Database B. Is this possible or did I miss something?
>
> The following failed:-
>
> if exists ( select * from dbo.sysobjects where id =
> object_id(N'[DATABASE_B].[dbo].[TABLE_A]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
>
> drop table [DATABASE_B].[dbo].[TABLE_A]
>
> TQVM.


From: Tibor Karaszi on
OBJECTPROPERTY is resolved in current database. It is likely to be resolved
to NULL causing the IF to be FALSE. I would skip that part. Alternatively,
you can do explicit SELECTs against the catalog views inside that database.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi



"GW" <GW(a)discussions.microsoft.com> wrote in message
news:7DD62CBF-86E4-4AAA-AE57-222CF775A1DB(a)microsoft.com...
> hi,
>
> need help,
>
> I have two databases. I have lines in SP running in Database A of which
> will
> check table existence in Database B but it did not find any table even the
> said table exists in Database B. Is this possible or did I miss something?
>
> The following failed:-
>
> if exists ( select * from dbo.sysobjects where id =
> object_id(N'[DATABASE_B].[dbo].[TABLE_A]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
>
> drop table [DATABASE_B].[dbo].[TABLE_A]
>
> TQVM.