ALTER DATABASE CURRENT - 异常 [英] ALTER DATABASE CURRENT - exception

查看:29
本文介绍了ALTER DATABASE CURRENT - 异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储过程,我可以在其中更改数据库属性.它在脚本中使用 ALTER DATABASE CURRENT.但我发现这在 2012 MSSQL 版本中运行良好,但在旧版本中出现异常.如何解决这个问题?

I have a stored procedure where i change DB properties . It uses ALTER DATABASE CURRENT in the script. But i found that this works fine in 2012 MSSQL version , but gives an exception in the older version. How to solve this problem ?

示例脚本内容:

  ALTER DATABASE CURRENT SET ANSI_PADDING OFF 
  GO

错误:

 Incorrect syntax near the keyword CURRENT

推荐答案

你可以在 sp_executesql 中使用匿名块 -

You can use anonymous block with sp_executesql -

declare @db_name varchar(64) 
declare @stat_sql nvarchar(256) 
begin   
  select @db_name = (select DB_NAME())
  set @stat_sql = N'ALTER DATABASE ' + @db_name + ' SET ANSI_PADDING OFF'
  EXECUTE sp_executesql @stat_sql
end

这篇关于ALTER DATABASE CURRENT - 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆