gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 19:48:18 26 4
gpt4 key购买 nike

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

-- 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 incorrectsettings: 'QUOTED_IDENTIFIER'. Verify that SET options are correct foruse with indexed views and/or indexes on computed columns and/orfiltered indexes and/or query notifications and/or XML data typemethods 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com