简体   繁体   中英

Permission to DROP Tables in SQL Server (T-SQL)

When running the DROP command (T-SQL) below on the SQL server the following message appears:

Cannot drop the table '[dbo].[TABELA]', because it does not exist or you do not have permission.

Comand

EXEC sp_MSForEachTable 'DROP TABLE [?]'

However, when I run another T-SQL command or a basic DROP Table, the above error message is not displayed, and the command is executed correctly.

DROP TABLE TABELA
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT all'

Both of the above commands work, what is the reason for the EXEC sp_MSForEachTable 'DROP TABLE [?]' Need a permission? and how to give this permission?

Try without the brackets. They seem to make the engine believe you want to drop a table named [dbo].[tablea] as sp_MSForEachTable already quotes if necessary. And of course a table named [dbo].[tablea] doesn't exist.

EXEC sp_MSForEachTable 'DROP TABLE ?'

db<>fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM