- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有谁知道一个查询,用于列出数据库中所有外键并应用 WITH NOCHECK
描述? (删除它们将提高性能和稳定性)。
最佳答案
以下内容将返回当前数据库中禁用的外键名称,即WITH NOCHECK
对于 SQL Server 2005/2008:
select * from sys.foreign_keys where is_disabled=1
-- drop table t1
-- drop table t2
create table t1(i int not null, fk int not null)
create table t2(i int not null)
-- create primary key on t2
alter table t2
add constraint pk_1 primary key (i)
-- create foriegn key on t1
alter table t1
add constraint fk_1 foreign key (fk)
references t2 (i)
--insert some records
insert t2 values(100)
insert t2 values(200)
insert t2 values(300)
insert t2 values(400)
insert t2 values(500)
insert t1 values(1,100)
insert t1 values(2,100)
insert t1 values(3,500)
insert t1 values(4,500)
----------------------------
-- 1. enabled and trusted
select name,is_disabled,is_not_trusted from sys.foreign_keys
GO
-- 2. disable the constraint
alter table t1 NOCHECK CONSTRAINT fk_1
select name,is_disabled,is_not_trusted from sys.foreign_keys
GO
-- 3. re-enable constraint, data isnt checked, so not trusted.
-- this means the optimizer will still have to check the column
alter table t1 CHECK CONSTRAINT fk_1
select name,is_disabled,is_not_trusted from sys.foreign_keys
GO
--4. drop the foreign key constraint & re-add
-- it making sure its checked
-- constraint is then enabled and trusted
alter table t1 DROP CONSTRAINT fk_1
alter table t1 WITH CHECK
add constraint fk_1 foreign key (fk)
references t2 (i)
select name,is_disabled,is_not_trusted from sys.foreign_keys
GO
--5. drop the foreign key constraint & add but dont check
-- constraint is then enabled, but not trusted
alter table t1 DROP CONSTRAINT fk_1
alter table t1 WITH NOCHECK
add constraint fk_1 foreign key (fk)
references t2 (i)
select name,is_disabled,is_not_trusted from sys.foreign_keys
GO
is_disabled
表示约束已禁用
isnottrusted
表示 SQL Server 不信任已根据外键表检查该列。
因此不能假设重新启用外键约束将会得到优化。为了确保优化器信任该列,最好删除外键约束并使用 WITH CHECK
选项重新创建它 (4.)
关于sql-server - 如何列出SQL Server中所有带有 "WITH NOCHECK"的外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1253623/
出于某种原因,当使用 SSDT 比较或修改表外键时,软件不会执行任何更改外键上设置的 NOCHECK 约束的操作。 这是表外键的脚本设置: 表: ALTER TABLE [dbo].[SurveyQu
我正在尝试删除并重新填充 SQL CE 上的测试数据。由于存在 FK 约束,我收到错误。通常在 Sql2005 中我会 ALTER TABLE [tablename] CHECK/NOCHECK CO
这些脚本之间有什么区别? ALTER TABLE Post_Send WITH NOCHECK CHECK CONSTRAINT [My_FOREIGN_KEY]; GO ALTER TABLE P
我正在使用 Visual Studio 2012,其中包含一个 SQL 数据库项目并针对该数据库运行数据库分析,并且它引发以下警告:带支票 |现有数据检查强制的 NOCHECK 选项被忽略。 我对错误
有谁知道一个查询,用于列出数据库中所有外键并应用 WITH NOCHECK 描述? (删除它们将提高性能和稳定性)。 最佳答案 以下内容将返回当前数据库中禁用的外键名称,即WITH NOCHECK 对
我们目前使用的是 Visual Studio 2010,并且有一个包含我们所有数据库对象的数据库项目。我们通常通过构建脚本将数据库部署到我们的 CI、QA 和 UAT 环境。对于生产,我们生成脚本并将
是否可以在带有 nocheck 约束的代码优先迁移中更改表?除了通过 Update-Database -Script 获取 SQL 脚本并修改 sql 语句外,我还没有找到任何方法来执行此操作。 最佳
我正在尝试同步不同数据库之间的架构。基本上,我在两个数据库上运行了任务 -> 使用 SQL Server Management Studio (2005) 生成脚本,并使用 diff 工具比较输出。
ALTER TABLE RoomReservation NOCHECK CONSTRAINT ALL ALTER TABLE RoomReservation ALTER COLUMN HotelNum
我是一名优秀的程序员,十分优秀!