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

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

        <bdo id='usaC5'></bdo><ul id='usaC5'></ul>
    2. <legend id='usaC5'><style id='usaC5'><dir id='usaC5'><q id='usaC5'></q></dir></style></legend>
      <tfoot id='usaC5'></tfoot>

      SQL Server:如何限制表包含单行?

      时间:2024-04-16
    3. <legend id='dULe1'><style id='dULe1'><dir id='dULe1'><q id='dULe1'></q></dir></style></legend>

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

            <bdo id='dULe1'></bdo><ul id='dULe1'></ul>
                  <tbody id='dULe1'></tbody>

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

                本文介绍了SQL Server:如何限制表包含单行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在我的应用程序的配置表中存储一行.我想强制此表只能包含一行.

                I want to store a single row in a configuration table for my application. I would like to enforce that this table can contain only one row.

                强制执行单行约束的最简单方法是什么?

                What is the simplest way to enforce the single row constraint ?

                推荐答案

                您确保其中一列只能包含一个值,然后将其设为主键(或应用唯一性约束).

                You make sure one of the columns can only contain one value, and then make that the primary key (or apply a uniqueness constraint).

                CREATE TABLE T1(
                    Lock char(1) not null,
                    /* Other columns */,
                    constraint PK_T1 PRIMARY KEY (Lock),
                    constraint CK_T1_Locked CHECK (Lock='X')
                )
                

                我在各种数据库中有许多这样的表,主要用于存储配置.知道如果配置项应该是 int 则更好,您将只会从 DB 中读取一个 int.

                I have a number of these tables in various databases, mostly for storing config. It's a lot nicer knowing that, if the config item should be an int, you'll only ever read an int from the DB.

                这篇关于SQL Server:如何限制表包含单行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:SQL Server 中数据库范围的唯一但简单的标识符 下一篇:MySQL - 一对一的关系?

                相关文章

                • <bdo id='wut6c'></bdo><ul id='wut6c'></ul>
                <tfoot id='wut6c'></tfoot>

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

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