Re: if exists +procedure error
- From: lszk <lszk86@xxxxxxxxx>
- Date: Sun, 28 Dec 2008 15:24:28 -0800 (PST)
Maybe you should first explain *WHY* you think
you need such a stored procedure, what you would gain by having it.
There might be a better way to achieve the same result.
I want to check a lot of tables, but I don't want to repeat code. So I
think, stored procedure will be ok for this.
This version should works properly.
create procedure spCheckTableInDatabase(
@TableName nvarchar(50)
)
as
begin
declare @sql nvarchar(60)
if exists
(select 1
from INFORMATION_SCHEMA.TABLES
where TABLE_SCHEMA = 'dbo'
and TABLE_NAME = @TableName)
begin
select @sql = 'drop table ' + @TableName
exec(@sql)
end
end
.
- Follow-Ups:
- Re: if exists +procedure error
- From: Plamen Ratchev
- Re: if exists +procedure error
- References:
- if exists +procedure error
- From: lszk
- Re: if exists +procedure error
- From: Hugo Kornelis
- if exists +procedure error
- Prev by Date: Re: if exists +procedure error
- Next by Date: Re: if exists +procedure error
- Previous by thread: Re: if exists +procedure error
- Next by thread: Re: if exists +procedure error
- Index(es):
Relevant Pages
|