sql-server - 删除所有表时出错 "DELETE failed because the following SET options have incorrect settings: ' QUOTED_IDENTIFIER'"

标签 sql-server tsql

我有一个脚本来删除数据库中的所有表,如下所示:

-- 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 行时,我在一些表中收到此错误:

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.

我没有任何索引 View ,所有外键和触发器都被禁用,所以我不知道是什么导致了这个错误。有什么想法吗?

最佳答案

将 SET 选项添加到删除调用中。

即使您禁用了 FK,这些仍然适用于错误中提到的其他项目。

这将解决任何已保存或环境设置

评论后编辑

EXEC sp_MSForEachTable 'SET QUOTED_IDENTIFIER ON; DELETE FROM ?'

关于sql-server - 删除所有表时出错 "DELETE failed because the following SET options have incorrect settings: ' QUOTED_IDENTIFIER'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8388272/

相关文章:

.net - 如何将 .Net 日期时间转换为 T-SQL 日期时间

sql - 运行存储过程

sql - 简单更改到查询对性能造成影响

SQL Server : Make all UPPER case to Proper Case/Title Case

sql - 检索插入的最后一行 Uniqueidentifier,它不是 IDENTITY

sql - 将充满逗号分隔值的 varchar 传递给 SQL Server IN 函数

sql - 具有多个联接的SQL JOIN语法错误

java - 使用 JDBC 驱动程序从 java 声明并使用 t-sql 变量

sql-server-2005 - Query just like Stackoverflow 5题24小时限制查询一样吗?

sql - 在 SQL 中查找子字符串