• <tfoot id='ybiIQ'></tfoot>
    <legend id='ybiIQ'><style id='ybiIQ'><dir id='ybiIQ'><q id='ybiIQ'></q></dir></style></legend>
      1. <small id='ybiIQ'></small><noframes id='ybiIQ'>

        • <bdo id='ybiIQ'></bdo><ul id='ybiIQ'></ul>

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

        我可以在 SQL Server 的添加列语句中创建命名默认约束吗?

        时间:2023-06-24

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

      2. <tfoot id='b2niQ'></tfoot>
            <bdo id='b2niQ'></bdo><ul id='b2niQ'></ul>

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

                  <legend id='b2niQ'><style id='b2niQ'><dir id='b2niQ'><q id='b2niQ'></q></dir></style></legend>
                  本文介绍了我可以在 SQL Server 的添加列语句中创建命名默认约束吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 SQL Server 中,我在表中有一个新列:

                  In SQL Server, I have a new column on a table:

                  ALTER TABLE t_tableName 
                      ADD newColumn NOT NULL
                  

                  这失败了,因为我在没有指定默认约束的情况下指定了 NOT NULL.该表不应具有默认约束.

                  This fails because I specify NOT NULL without specifying a default constraint. The table should not have a default constraint.

                  为了解决这个问题,我可以使用默认约束创建表,然后将其删除.

                  To get around this, I could create the table with the default constraint and then remove it.

                  但是,似乎没有任何方法可以指定默认约束应命名为该语句的一部分,因此我摆脱它的唯一方法是使用存储过程在sys.default_constraints 表.

                  However, there doesn't appear to be any way to specify that the default constraint should be named as part of this statement, so my only way to get rid of it is to have a stored procedure which looks it up in the sys.default_constraints table.

                  对于可能经常发生的操作来说,这有点混乱/冗长.有没有人对此有更好的解决方案?

                  This is a bit messy/verbose for an operation which is likely to happen a lot. Does anyone have any better solutions for this?

                  推荐答案

                  这应该有效:

                  ALTER TABLE t_tableName 
                      ADD newColumn VARCHAR(50)
                      CONSTRAINT YourContraintName DEFAULT '' NOT NULL
                  

                  这篇关于我可以在 SQL Server 的添加列语句中创建命名默认约束吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 SQL Server 中重命名表? 下一篇:SQL Server - 将数据库列从 varchar 更新为 nvarchar(如果还不是 nvarchar)的脚本

                  相关文章

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

                        <bdo id='rhTcc'></bdo><ul id='rhTcc'></ul>

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

                    3. <legend id='rhTcc'><style id='rhTcc'><dir id='rhTcc'><q id='rhTcc'></q></dir></style></legend>