【发布时间】:2019-12-08 16:03:14
【问题描述】:
我想知道是否可以删除带有SMO 对象(SQL Server 和 C#)的表上的所有约束?
事实上,我想知道下面的SQL查询等价于SMO对象:
ALTER TABLE TableName NOCHECK CONSTRAINT ALL
现在,我正在尝试在索引集合中查找约束状态,但找不到约束详细信息。
这是我的“非工作”代码:
Server server = new Server(new ServerConnection(sqlConnectionSmo));
foreach (Database db in server.Databases)
{
foreach (Table table in db.Tables)
{
// Objective: 'ALTER TABLE YourTableName NOCHECK CONSTRAINT ALL'
// SMO index vs constraint ?
foreach (Index index in table.Indexes)
{
if (index.IndexKeyType = **Constraint??**)
{
index.Disable;
}
}
}
}
知道这是否可能吗?
【问题讨论】:
-
我认为您需要 checks 属性。然后您可以遍历constraints。不过我在这里没有很多经验。
标签: sql sql-server ssms smo check-constraints