继续在t-sql中获取语法错误

时间:2014-06-09 08:11:50

标签: sql sql-server sql-server-2005 sql-server-2008-r2

我已经创建了证书,现在我想删除证书签名并删除证书。当我直接提供证书名称时,它正在工作,但是当我使用局部变量提供名称时,它会给我语法错误。

我也试过不同的数据类型

text, varbinary(max), char(200), varchar(200), nvarchar(200)

这些数据类型都不起作用。

declare @certificate nvarchar(200) 
set @certificate = 'ITManagerCertificate'

begin transaction
use DBwork

-- remove signature from stored procedure
drop signature from Report_Manager
by certificate @certificate

-- drop certificate
--DROP CERTIFICATE @certificate 

if @@ERROR > 0
begin 
   rollback transaction
end 
else begin
   commit transaction
end

1 个答案:

答案 0 :(得分:1)

试试这个

declare @certificate nvarchar(200)
declare @sql nvarchar(1000) 
set @certificate = N'ITManagerCertificate'

begin transaction
use DBwork
--Remove Signature from Store procedure
set @sql= N'drop signature from Report_Manager
by certificate '+ @certificate
execute sp_executesql @sql
--Drop certificate
--DROP CERTIFICATE @certificate 

if @@ERROR > 0
begin 
rollback transaction
end 
else begin
commit transaction
end