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:如何限制表包含单行?

      SQL Server: how to constrain a table to contain a single row?(SQL Server:如何限制表包含单行?)
    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 query to group by day(按天分组的 SQL 查询)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                sql group by versus distinct(sql group by 与不同)
                How to return a incremental group number per group in SQL(如何在SQL中返回每个组的增量组号)
                Count number of records returned by group by(统计分组返回的记录数)
                SQL GROUP BY CASE statement with aggregate function(带聚合函数的 SQL GROUP BY CASE 语句)
                • <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>
                    <tbody id='wut6c'></tbody>
                  1. <legend id='wut6c'><style id='wut6c'><dir id='wut6c'><q id='wut6c'></q></dir></style></legend>

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