Click to See Complete Forum and Search --> : DROP TABLE
I want to write a stored procedure that drops a set of temp tables. However,
I'm not sure how to test for the existence of a table before executing.
For instance,
DROP TABLE tmpJanTerm
DROP TABLE tmpFebTerm
DROP TABLE tmpMarchTerm
will fail if any one of these tables don't exist. Any thoughts??
If a table listed in your procedure doesn't exist, execution will go to the
next line. So if a table doesn't exist, it will not cause the entire procedure
to fail. Try it in query analyzer.
"Kyle" wrote:
>
>I want to write a stored procedure that drops a set of temp tables. However,
>I'm not sure how to test for the existence of a table before executing.
>For instance,
>
>DROP TABLE tmpJanTerm
>DROP TABLE tmpFebTerm
>DROP TABLE tmpMarchTerm
>
>
>will fail if any one of these tables don't exist. Any thoughts??
>
>
M.A. Leone
03-28-2000, 11:37 PM
if exists (SELECT name FROM sysobjects WHERE name = "tmpJanTerm" and type =
"u")
BEGIN
DROP TABLE tmpJanTerm
END
GO
if exists (SELECT name FROM sysobjects WHERE name = "tmpFebTerm" and type =
"u")
BEGIN
DROP TABLE tmpFebTerm
END
GO
Etc.
Kyle <kphillips@cisconinc.com> wrote in message
news:38d92e2b$1@news.devx.com...
I want to write a stored procedure that drops a set of temp tables.
However,
I'm not sure how to test for the existence of a table before executing.
For instance,
DROP TABLE tmpJanTerm
DROP TABLE tmpFebTerm
DROP TABLE tmpMarchTerm
will fail if any one of these tables don't exist. Any thoughts??
devx.com
Copyright WebMediaBrands Inc. All Rights Reserved