executing a test in sql server 2005
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开发者_JAVA技巧 error
Could not find stored procedure 'DROP TABLE bkp_anish_test'.
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
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')
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;');
精彩评论