Error deleting all tables quot;DELETE failed because the following SET options have incorrect settings: #39;QUOTED_IDENTIFIER#39;quot;(删除所有表时出错“删除失败,因为以下 SET 选项的设置不正确:‘QUOTED_IDENTIFIER’;)
问题描述
我有一个脚本来删除我的数据库中的所有表,如下所示:
I have a script to delete all tables in my database that looks like this:
-- Disable all constraints
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT all'
-- Disable all triggers
EXEC EnableAllTriggers @Enable = 0
-- Delete data in all tables
EXEC sp_MSForEachTable 'DELETE FROM ?'
-- Dnable all constraints
EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'
-- Reseed identity columns
EXEC sp_MSForEachTable 'DBCC CHECKIDENT (''?'', RESEED, 0)'
-- Enable all triggers
EXEC EnableAllTriggers @Enable = 1
当它碰到 DELETE 行时,我收到一些表的错误:
When it hits the DELETE line I get this error for a few of the tables:
DELETE 失败,因为以下 SET 选项不正确设置:'QUOTED_IDENTIFIER'.验证 SET 选项是否正确与索引视图和/或计算列和/或索引一起使用过滤索引和/或查询通知和/或 XML 数据类型方法和/或空间索引操作.
DELETE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.
我没有任何索引视图,所有外键和触发器都被禁用,所以我不知道是什么导致了这个错误.有什么想法吗?
I don't have any indexed views, all foreign keys and triggers are disabled, so I don't know what is causing this error. Any ideas?
推荐答案
将 SET 选项添加到删除调用中.
Add the SET options to the delete call.
这些仍然适用于错误中提到的其他项目,即使您禁用了 FK.
These still apply to the other items mentioned in the error, even though you disabled FKs.
这将解决任何已保存或环境设置
This will work around any saved or environment settings
评论后编辑
EXEC sp_MSForEachTable 'SET QUOTED_IDENTIFIER ON; DELETE FROM ?'
这篇关于删除所有表时出错“删除失败,因为以下 SET 选项的设置不正确:‘QUOTED_IDENTIFIER’";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:删除所有表时出错“删除失败,因为以下 SET 选项
基础教程推荐
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
