Home All Groups Group Topic Archive Search About

Stored procedure/trigger contain reference to a non-existing objec

Author
3 Mar 2006 7:21 AM
Peter
This question is for both SQL Server 2000 and SQL Server 2005.

Are there any problem in creating/compiling a stored procedure/trigger if it 
contains reference to a non-existing object such as table or stored
procedure? 
Of course, the coding reference such object will be executed only if the
object exists.

Thanks.

Author
3 Mar 2006 7:23 AM
oj
defered name resolution in sql2k/5 will allow you to do this.

e.g.
create proc usp
as
select * from nonexistenttable
go


--
-oj



Show quote
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:6B46255E-7889-470B-BF70-DC50E87A5B46@microsoft.com...
> This question is for both SQL Server 2000 and SQL Server 2005.
>
> Are there any problem in creating/compiling a stored procedure/trigger if
> it
> contains reference to a non-existing object such as table or stored
> procedure?
> Of course, the coding reference such object will be executed only if the
> object exists.
>
> Thanks.
>
Author
3 Mar 2006 7:32 AM
Peter
Hi oj,

Are there any setting to disallow deferred name resolution?


Peter

Show quote
"oj" wrote:

> defered name resolution in sql2k/5 will allow you to do this.
>
> e.g.
> create proc usp
> as
> select * from nonexistenttable
> go
>
>
> --
> -oj
>
>
>
> "Peter" <Pe***@discussions.microsoft.com> wrote in message
> news:6B46255E-7889-470B-BF70-DC50E87A5B46@microsoft.com...
> > This question is for both SQL Server 2000 and SQL Server 2005.
> >
> > Are there any problem in creating/compiling a stored procedure/trigger if
> > it
> > contains reference to a non-existing object such as table or stored
> > procedure?
> > Of course, the coding reference such object will be executed only if the
> > object exists.
> >
> > Thanks.
> >
>
>
>
Author
3 Mar 2006 7:39 AM
Peter
Hi oj,

I just read the deferred name resolution in SQL Server 2000 BOL.  It seems
that it is Ok to create but not during execution time. 


Peter

Show quote
"oj" wrote:

> defered name resolution in sql2k/5 will allow you to do this.
>
> e.g.
> create proc usp
> as
> select * from nonexistenttable
> go
>
>
> --
> -oj
>
>
>
> "Peter" <Pe***@discussions.microsoft.com> wrote in message
> news:6B46255E-7889-470B-BF70-DC50E87A5B46@microsoft.com...
> > This question is for both SQL Server 2000 and SQL Server 2005.
> >
> > Are there any problem in creating/compiling a stored procedure/trigger if
> > it
> > contains reference to a non-existing object such as table or stored
> > procedure?
> > Of course, the coding reference such object will be executed only if the
> > object exists.
> >
> > Thanks.
> >
>
>
>
Author
3 Mar 2006 7:44 AM
oj
yup, the defered name resolution feature only allows you to compile/create
the sproc.

--
-oj



Show quote
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:563D0BB5-7455-4352-8BB8-28C1C42DF886@microsoft.com...
> Hi oj,
>
> I just read the deferred name resolution in SQL Server 2000 BOL.  It seems
> that it is Ok to create but not during execution time.
>
>
> Peter
>
> "oj" wrote:
>
>> defered name resolution in sql2k/5 will allow you to do this.
>>
>> e.g.
>> create proc usp
>> as
>> select * from nonexistenttable
>> go
>>
>>
>> --
>> -oj
>>
>>
>>
>> "Peter" <Pe***@discussions.microsoft.com> wrote in message
>> news:6B46255E-7889-470B-BF70-DC50E87A5B46@microsoft.com...
>> > This question is for both SQL Server 2000 and SQL Server 2005.
>> >
>> > Are there any problem in creating/compiling a stored procedure/trigger
>> > if
>> > it
>> > contains reference to a non-existing object such as table or stored
>> > procedure?
>> > Of course, the coding reference such object will be executed only if
>> > the
>> > object exists.
>> >
>> > Thanks.
>> >
>>
>>
>>
Author
3 Mar 2006 8:00 AM
Peter
Hi oj,

Anyway to workaround this? I need to write coding that only run if the
object exists otherwise skip coding.

For example,

if table1 exists,
  select * from table1
else
  select * from table2



Show quote
"oj" wrote:

> yup, the defered name resolution feature only allows you to compile/create
> the sproc.
>
> --
> -oj
>
>
>
> "Peter" <Pe***@discussions.microsoft.com> wrote in message
> news:563D0BB5-7455-4352-8BB8-28C1C42DF886@microsoft.com...
> > Hi oj,
> >
> > I just read the deferred name resolution in SQL Server 2000 BOL.  It seems
> > that it is Ok to create but not during execution time.
> >
> >
> > Peter
> >
> > "oj" wrote:
> >
> >> defered name resolution in sql2k/5 will allow you to do this.
> >>
> >> e.g.
> >> create proc usp
> >> as
> >> select * from nonexistenttable
> >> go
> >>
> >>
> >> --
> >> -oj
> >>
> >>
> >>
> >> "Peter" <Pe***@discussions.microsoft.com> wrote in message
> >> news:6B46255E-7889-470B-BF70-DC50E87A5B46@microsoft.com...
> >> > This question is for both SQL Server 2000 and SQL Server 2005.
> >> >
> >> > Are there any problem in creating/compiling a stored procedure/trigger
> >> > if
> >> > it
> >> > contains reference to a non-existing object such as table or stored
> >> > procedure?
> >> > Of course, the coding reference such object will be executed only if
> >> > the
> >> > object exists.
> >> >
> >> > Thanks.
> >> >
> >>
> >>
> >>
>
>
>
Author
3 Mar 2006 4:56 PM
oj
You can do this with dynamic sql.

e.g.
if object_id('tb1') is not null
exec('select * from tb1')
if object_id('tb2') is not null
exec('select * from tb2')


--
-oj



Show quote
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:83F93920-F498-4633-9886-9882C5D519DF@microsoft.com...
> Hi oj,
>
> Anyway to workaround this? I need to write coding that only run if the
> object exists otherwise skip coding.
>
> For example,
>
> if table1 exists,
>  select * from table1
> else
>  select * from table2
>
>
>
> "oj" wrote:
>
>> yup, the defered name resolution feature only allows you to
>> compile/create
>> the sproc.
>>
>> --
>> -oj
>>
>>
>>
>> "Peter" <Pe***@discussions.microsoft.com> wrote in message
>> news:563D0BB5-7455-4352-8BB8-28C1C42DF886@microsoft.com...
>> > Hi oj,
>> >
>> > I just read the deferred name resolution in SQL Server 2000 BOL.  It
>> > seems
>> > that it is Ok to create but not during execution time.
>> >
>> >
>> > Peter
>> >
>> > "oj" wrote:
>> >
>> >> defered name resolution in sql2k/5 will allow you to do this.
>> >>
>> >> e.g.
>> >> create proc usp
>> >> as
>> >> select * from nonexistenttable
>> >> go
>> >>
>> >>
>> >> --
>> >> -oj
>> >>
>> >>
>> >>
>> >> "Peter" <Pe***@discussions.microsoft.com> wrote in message
>> >> news:6B46255E-7889-470B-BF70-DC50E87A5B46@microsoft.com...
>> >> > This question is for both SQL Server 2000 and SQL Server 2005.
>> >> >
>> >> > Are there any problem in creating/compiling a stored
>> >> > procedure/trigger
>> >> > if
>> >> > it
>> >> > contains reference to a non-existing object such as table or stored
>> >> > procedure?
>> >> > Of course, the coding reference such object will be executed only if
>> >> > the
>> >> > object exists.
>> >> >
>> >> > Thanks.
>> >> >
>> >>
>> >>
>> >>
>>
>>
>>

AddThis Social Bookmark Button