在sql server 2005中执行测试

发布于 2024-10-07 06:54:57 字数 231 浏览 0 评论 0原文

当我执行以下...

EXEC 'DROP TABLE bkp_anish_test'

'DROP TABLE bkp_anish_test' 是动态构建 sql 查询)

时,我收到以下错误

找不到存储过程“DROP TABLE bkp_anish_test”。

When I am executing following ...

EXEC 'DROP TABLE bkp_anish_test'

('DROP TABLE bkp_anish_test' is a dynamically build sql query)

I am getting following error

Could not find stored procedure 'DROP TABLE bkp_anish_test'.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里寻她 2024-10-14 06:54:57

改为执行此操作:

exec sp_executesql N'DROP TABLE bkp_anish_test'

或者对于动态构建字符串的情况:

declare @MyTable nvarchar(100)
set @MyTable = N'bkp_anish_test'

declare @sql nvarchar(100)
set @sql = N'DROP TABLE ' + @MyTable
exec sp_executesql @sql

Do this instead:

exec sp_executesql N'DROP TABLE bkp_anish_test'

or for the case of a dynamically built string:

declare @MyTable nvarchar(100)
set @MyTable = N'bkp_anish_test'

declare @sql nvarchar(100)
set @sql = N'DROP TABLE ' + @MyTable
exec sp_executesql @sql
对你而言 2024-10-14 06:54:57

尝试在命令中添加括号。如果要使用 EXEC 命令,则必须在运行 SQL 语句时包含它们。

EXEC ('DROP TABLE bkp_anish_test')

Try adding parentheses to your command. You must include them when running a SQL statement, if you're going to use the EXEC command.

EXEC ('DROP TABLE bkp_anish_test')
人间不值得 2024-10-14 06:54:57

您不需要使用 EXEC 来运行 sql 语句。 则运行,试试这个

DROP TABLE bkp_anish_test

在查询编辑器中,如果表位于 xyz 数据库中,

 EXEC ('USE xyz ; DROP TABLE bkp_anish_test;');

You dont need to use EXEC to run the sql statement. In the query editor, just run

DROP TABLE bkp_anish_test

if the table is in xyz database, try this

 EXEC ('USE xyz ; DROP TABLE bkp_anish_test;');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文