<bdo id='Qi1mA'></bdo><ul id='Qi1mA'></ul>
  1. <legend id='Qi1mA'><style id='Qi1mA'><dir id='Qi1mA'><q id='Qi1mA'></q></dir></style></legend>

    <small id='Qi1mA'></small><noframes id='Qi1mA'>

  2. <tfoot id='Qi1mA'></tfoot>
    <i id='Qi1mA'><tr id='Qi1mA'><dt id='Qi1mA'><q id='Qi1mA'><span id='Qi1mA'><b id='Qi1mA'><form id='Qi1mA'><ins id='Qi1mA'></ins><ul id='Qi1mA'></ul><sub id='Qi1mA'></sub></form><legend id='Qi1mA'></legend><bdo id='Qi1mA'><pre id='Qi1mA'><center id='Qi1mA'></center></pre></bdo></b><th id='Qi1mA'></th></span></q></dt></tr></i><div id='Qi1mA'><tfoot id='Qi1mA'></tfoot><dl id='Qi1mA'><fieldset id='Qi1mA'></fieldset></dl></div>

      由位列控制的 UNIQUE 约束

      UNIQUE constraint controlled by a bit column(由位列控制的 UNIQUE 约束)
      <legend id='t7bWs'><style id='t7bWs'><dir id='t7bWs'><q id='t7bWs'></q></dir></style></legend>

          <tfoot id='t7bWs'></tfoot>

            1. <small id='t7bWs'></small><noframes id='t7bWs'>

            2. <i id='t7bWs'><tr id='t7bWs'><dt id='t7bWs'><q id='t7bWs'><span id='t7bWs'><b id='t7bWs'><form id='t7bWs'><ins id='t7bWs'></ins><ul id='t7bWs'></ul><sub id='t7bWs'></sub></form><legend id='t7bWs'></legend><bdo id='t7bWs'><pre id='t7bWs'><center id='t7bWs'></center></pre></bdo></b><th id='t7bWs'></th></span></q></dt></tr></i><div id='t7bWs'><tfoot id='t7bWs'></tfoot><dl id='t7bWs'><fieldset id='t7bWs'></fieldset></dl></div>
                <tbody id='t7bWs'></tbody>
              • <bdo id='t7bWs'></bdo><ul id='t7bWs'></ul>
              • 本文介绍了由位列控制的 UNIQUE 约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一张桌子,类似于

                FieldsOnForms(
                 FieldID int (FK_Fields)
                 FormID int (FK_Forms)
                 isDeleted bit
                )
                

                这对 (FieldID,FormID) 应该是唯一的,但前提是该行未被删除 (isDeleted=0).

                The pair (FieldID,FormID) should be unique, BUT only if the row is not deleted (isDeleted=0).

                是否可以在 SQLServer 2008 中定义这样的约束?(不使用触发器)

                Is it possible to define such a constraint in SQLServer 2008? (without using triggers)

                附言将 (FieldID, FormID, isDeleted) 设置为唯一增加了将一行标记为已删除的可能性,但我希望有机会将 n 行(每个 FieldID,FormID)设置为 isDeleted = 1,并且只有一行与isDeleted = 0

                P.S. Setting (FieldID, FormID, isDeleted) to be unique adds the possibility to mark one row as deleted, but i would like to have the chance to set n rows (per FieldID,FormID) to isDeleted = 1, and to have only one with isDeleted = 0

                推荐答案

                您可以拥有唯一的索引,使用 SQL Server 2008 过滤索引 功能,或者您可以对视图应用 UNIQUE 索引(穷人的过滤索引,适用于早期版本),但您不能具有您所描述的 UNIQUE 约束.

                You can have a unique index, using the SQL Server 2008 filtered indexes feature, or you can apply a UNIQUE index against a view (poor man's filtered index, works against earlier versions), but you cannot have a UNIQUE constraint such as you've described.

                过滤索引示例:

                 CREATE UNIQUE NONCLUSTERED INDEX IX_FieldsOnForms_NonDeletedUnique ON FieldsOnForms (FieldID,FormID) WHERE isDeleted=0
                

                这篇关于由位列控制的 UNIQUE 约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                SQL query to group by day(按天分组的 SQL 查询)
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)

                <small id='rZ0EL'></small><noframes id='rZ0EL'>

                      <tbody id='rZ0EL'></tbody>
                      <legend id='rZ0EL'><style id='rZ0EL'><dir id='rZ0EL'><q id='rZ0EL'></q></dir></style></legend>
                      • <tfoot id='rZ0EL'></tfoot>
                          <bdo id='rZ0EL'></bdo><ul id='rZ0EL'></ul>
                        • <i id='rZ0EL'><tr id='rZ0EL'><dt id='rZ0EL'><q id='rZ0EL'><span id='rZ0EL'><b id='rZ0EL'><form id='rZ0EL'><ins id='rZ0EL'></ins><ul id='rZ0EL'></ul><sub id='rZ0EL'></sub></form><legend id='rZ0EL'></legend><bdo id='rZ0EL'><pre id='rZ0EL'><center id='rZ0EL'></center></pre></bdo></b><th id='rZ0EL'></th></span></q></dt></tr></i><div id='rZ0EL'><tfoot id='rZ0EL'></tfoot><dl id='rZ0EL'><fieldset id='rZ0EL'></fieldset></dl></div>