SQLServer add a default value for a columnAdd DEFAULT to existing columnIndexing - Uniqueidentifier Foreign Key or Intermediary mapping table?SQL set allowed values for a columnWhy is column default value not portable through different RDBMS?Default value for “microtime” column in MySQLdeteriorating stored procedure running timesDefault value for UUID column in PostgresSet Field To Have Default Value Of AnotherHow to set column DEFAULT using value of a variableCan you use an inserted variable in a default constraint

Apex Class Deployment: duplicate value found: <unknown> duplicates value on record with id: <unknown>

Movie in a trailer park named Paradise and a boy playing a video game then being recruited by aliens to fight in space

Why would anyone even use a Portkey?

Can the Raspberry Pi 4 better distribute Python scripts to all four cores?

How did installing this RPM create a file?

Why do I need two parameters in an HTTP parameter pollution attack?

How did researchers find articles before the Internet and the computer era?

Who are these Discworld wizards from this picture?

What does grep -v "grep" mean and do?

Could a Weapon of Mass Destruction, targeting only humans, be developed?

SQLServer add a default value for a column

My colleague is constantly blaming me for his errors

I hit a pipe with a mower and now it won't turn

Step into the Octagram

Who voices the character "Finger" in The Fifth Element?

Is it okay to fade a human face just to create some space to place important content over it?

Security Patch SUPEE-11155 - Possible issues?

How can my story take place on Earth without referring to our existing cities and countries?

Do the 26 richest billionaires own as much wealth as the poorest 3.8 billion people?

How to get a character's limb regrown at 3rd level?

Could human civilization live 150 years in a nuclear-powered aircraft carrier colony without resorting to mass killing/ cannibalism?

Handling a player (unintentionally) stealing the spotlight

Is there a legal way for US presidents to extend their terms beyond four years?

Losing queen and then winning the game



SQLServer add a default value for a column


Add DEFAULT to existing columnIndexing - Uniqueidentifier Foreign Key or Intermediary mapping table?SQL set allowed values for a columnWhy is column default value not portable through different RDBMS?Default value for “microtime” column in MySQLdeteriorating stored procedure running timesDefault value for UUID column in PostgresSet Field To Have Default Value Of AnotherHow to set column DEFAULT using value of a variableCan you use an inserted variable in a default constraint






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am using MS SQL Server. I have an "action" table with an "action_type" column that I want to set a default value of "to do" for. My DDL in MS SQL Studio errors! I have read many many articles trying to work out what I am doing wrong but nothing seems to work. The DDL is as follows, the table CREATE works, and the ALTER fails.



CREATE TABLE "action"
( "action" INT IDENTITY(1,1)
, "name" VARCHAR(250) NOT NULL
, "owner" VARCHAR(50)
, "action_type" VARCHAR(50) NOT NULL
, "due_date" DATETIME
, "done_date" DATETIME
, "successful" BIT NOT NULL
, "job" INT
, "contract" INT
, "person" INT
, "description" VARCHAR(MAX)
, "deliverable" VARCHAR(MAX)
, "outcome" VARCHAR(MAX)
, "source" VARCHAR(50)
, "notes" VARCHAR(MAX)
);
ALTER TABLE "action"
ADD CONSTRAINT "df_action_0" DEFAULT "To Do" FOR "action_type";


The ALTER statement returns error




Msg 128, Level 15, State 1, Line 4 The name "To Do" is not permitted
in this context. Valid expressions are constants, constant
expressions, and (in some contexts) variables. Column names are not
permitted.




Based on various articles I have tried replacing "To Do" with 'To Do', N'To Do', ("To Do") and others, nothing works.










share|improve this question







New contributor



Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    1















    I am using MS SQL Server. I have an "action" table with an "action_type" column that I want to set a default value of "to do" for. My DDL in MS SQL Studio errors! I have read many many articles trying to work out what I am doing wrong but nothing seems to work. The DDL is as follows, the table CREATE works, and the ALTER fails.



    CREATE TABLE "action"
    ( "action" INT IDENTITY(1,1)
    , "name" VARCHAR(250) NOT NULL
    , "owner" VARCHAR(50)
    , "action_type" VARCHAR(50) NOT NULL
    , "due_date" DATETIME
    , "done_date" DATETIME
    , "successful" BIT NOT NULL
    , "job" INT
    , "contract" INT
    , "person" INT
    , "description" VARCHAR(MAX)
    , "deliverable" VARCHAR(MAX)
    , "outcome" VARCHAR(MAX)
    , "source" VARCHAR(50)
    , "notes" VARCHAR(MAX)
    );
    ALTER TABLE "action"
    ADD CONSTRAINT "df_action_0" DEFAULT "To Do" FOR "action_type";


    The ALTER statement returns error




    Msg 128, Level 15, State 1, Line 4 The name "To Do" is not permitted
    in this context. Valid expressions are constants, constant
    expressions, and (in some contexts) variables. Column names are not
    permitted.




    Based on various articles I have tried replacing "To Do" with 'To Do', N'To Do', ("To Do") and others, nothing works.










    share|improve this question







    New contributor



    Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      1












      1








      1








      I am using MS SQL Server. I have an "action" table with an "action_type" column that I want to set a default value of "to do" for. My DDL in MS SQL Studio errors! I have read many many articles trying to work out what I am doing wrong but nothing seems to work. The DDL is as follows, the table CREATE works, and the ALTER fails.



      CREATE TABLE "action"
      ( "action" INT IDENTITY(1,1)
      , "name" VARCHAR(250) NOT NULL
      , "owner" VARCHAR(50)
      , "action_type" VARCHAR(50) NOT NULL
      , "due_date" DATETIME
      , "done_date" DATETIME
      , "successful" BIT NOT NULL
      , "job" INT
      , "contract" INT
      , "person" INT
      , "description" VARCHAR(MAX)
      , "deliverable" VARCHAR(MAX)
      , "outcome" VARCHAR(MAX)
      , "source" VARCHAR(50)
      , "notes" VARCHAR(MAX)
      );
      ALTER TABLE "action"
      ADD CONSTRAINT "df_action_0" DEFAULT "To Do" FOR "action_type";


      The ALTER statement returns error




      Msg 128, Level 15, State 1, Line 4 The name "To Do" is not permitted
      in this context. Valid expressions are constants, constant
      expressions, and (in some contexts) variables. Column names are not
      permitted.




      Based on various articles I have tried replacing "To Do" with 'To Do', N'To Do', ("To Do") and others, nothing works.










      share|improve this question







      New contributor



      Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I am using MS SQL Server. I have an "action" table with an "action_type" column that I want to set a default value of "to do" for. My DDL in MS SQL Studio errors! I have read many many articles trying to work out what I am doing wrong but nothing seems to work. The DDL is as follows, the table CREATE works, and the ALTER fails.



      CREATE TABLE "action"
      ( "action" INT IDENTITY(1,1)
      , "name" VARCHAR(250) NOT NULL
      , "owner" VARCHAR(50)
      , "action_type" VARCHAR(50) NOT NULL
      , "due_date" DATETIME
      , "done_date" DATETIME
      , "successful" BIT NOT NULL
      , "job" INT
      , "contract" INT
      , "person" INT
      , "description" VARCHAR(MAX)
      , "deliverable" VARCHAR(MAX)
      , "outcome" VARCHAR(MAX)
      , "source" VARCHAR(50)
      , "notes" VARCHAR(MAX)
      );
      ALTER TABLE "action"
      ADD CONSTRAINT "df_action_0" DEFAULT "To Do" FOR "action_type";


      The ALTER statement returns error




      Msg 128, Level 15, State 1, Line 4 The name "To Do" is not permitted
      in this context. Valid expressions are constants, constant
      expressions, and (in some contexts) variables. Column names are not
      permitted.




      Based on various articles I have tried replacing "To Do" with 'To Do', N'To Do', ("To Do") and others, nothing works.







      sql-server constraint alter-table default-value






      share|improve this question







      New contributor



      Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 8 hours ago









      Mark KortinkMark Kortink

      61 bronze badge




      61 bronze badge




      New contributor



      Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      Mark Kortink is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes


















          4














          It's your quotes. If you remove those, and change your literal to use single quotes, you should be fine. SQL Servers DEFAULT is SET QUOTED_IDENTIFIER ON and with this literals must be delimited by single quotation marks. So, you really only need to change this part:



          DEMO



          ALTER TABLE "action"
          ADD CONSTRAINT "df_action_0" DEFAULT 'To Do' FOR "action_type";


          Though, you will more commonly see double quotes not used in this manner, and instead your DDL would be written as:



          CREATE TABLE action
          ( action INT IDENTITY(1,1)
          , name VARCHAR(250) NOT NULL
          , owner VARCHAR(50)
          , action_type VARCHAR(50) NOT NULL
          , due_date DATETIME
          , done_date DATETIME
          , successful BIT NOT NULL
          , job INT
          , contract INT
          , person INT
          , description VARCHAR(MAX)
          , deliverable VARCHAR(MAX)
          , outcome VARCHAR(MAX)
          , source VARCHAR(50)
          , notes VARCHAR(MAX)
          );

          ALTER TABLE action
          ADD CONSTRAINT df_action_0 DEFAULT 'To Do' FOR action_type;





          share|improve this answer



























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "182"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );






            Mark Kortink is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f241410%2fsqlserver-add-a-default-value-for-a-column%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            It's your quotes. If you remove those, and change your literal to use single quotes, you should be fine. SQL Servers DEFAULT is SET QUOTED_IDENTIFIER ON and with this literals must be delimited by single quotation marks. So, you really only need to change this part:



            DEMO



            ALTER TABLE "action"
            ADD CONSTRAINT "df_action_0" DEFAULT 'To Do' FOR "action_type";


            Though, you will more commonly see double quotes not used in this manner, and instead your DDL would be written as:



            CREATE TABLE action
            ( action INT IDENTITY(1,1)
            , name VARCHAR(250) NOT NULL
            , owner VARCHAR(50)
            , action_type VARCHAR(50) NOT NULL
            , due_date DATETIME
            , done_date DATETIME
            , successful BIT NOT NULL
            , job INT
            , contract INT
            , person INT
            , description VARCHAR(MAX)
            , deliverable VARCHAR(MAX)
            , outcome VARCHAR(MAX)
            , source VARCHAR(50)
            , notes VARCHAR(MAX)
            );

            ALTER TABLE action
            ADD CONSTRAINT df_action_0 DEFAULT 'To Do' FOR action_type;





            share|improve this answer





























              4














              It's your quotes. If you remove those, and change your literal to use single quotes, you should be fine. SQL Servers DEFAULT is SET QUOTED_IDENTIFIER ON and with this literals must be delimited by single quotation marks. So, you really only need to change this part:



              DEMO



              ALTER TABLE "action"
              ADD CONSTRAINT "df_action_0" DEFAULT 'To Do' FOR "action_type";


              Though, you will more commonly see double quotes not used in this manner, and instead your DDL would be written as:



              CREATE TABLE action
              ( action INT IDENTITY(1,1)
              , name VARCHAR(250) NOT NULL
              , owner VARCHAR(50)
              , action_type VARCHAR(50) NOT NULL
              , due_date DATETIME
              , done_date DATETIME
              , successful BIT NOT NULL
              , job INT
              , contract INT
              , person INT
              , description VARCHAR(MAX)
              , deliverable VARCHAR(MAX)
              , outcome VARCHAR(MAX)
              , source VARCHAR(50)
              , notes VARCHAR(MAX)
              );

              ALTER TABLE action
              ADD CONSTRAINT df_action_0 DEFAULT 'To Do' FOR action_type;





              share|improve this answer



























                4












                4








                4







                It's your quotes. If you remove those, and change your literal to use single quotes, you should be fine. SQL Servers DEFAULT is SET QUOTED_IDENTIFIER ON and with this literals must be delimited by single quotation marks. So, you really only need to change this part:



                DEMO



                ALTER TABLE "action"
                ADD CONSTRAINT "df_action_0" DEFAULT 'To Do' FOR "action_type";


                Though, you will more commonly see double quotes not used in this manner, and instead your DDL would be written as:



                CREATE TABLE action
                ( action INT IDENTITY(1,1)
                , name VARCHAR(250) NOT NULL
                , owner VARCHAR(50)
                , action_type VARCHAR(50) NOT NULL
                , due_date DATETIME
                , done_date DATETIME
                , successful BIT NOT NULL
                , job INT
                , contract INT
                , person INT
                , description VARCHAR(MAX)
                , deliverable VARCHAR(MAX)
                , outcome VARCHAR(MAX)
                , source VARCHAR(50)
                , notes VARCHAR(MAX)
                );

                ALTER TABLE action
                ADD CONSTRAINT df_action_0 DEFAULT 'To Do' FOR action_type;





                share|improve this answer















                It's your quotes. If you remove those, and change your literal to use single quotes, you should be fine. SQL Servers DEFAULT is SET QUOTED_IDENTIFIER ON and with this literals must be delimited by single quotation marks. So, you really only need to change this part:



                DEMO



                ALTER TABLE "action"
                ADD CONSTRAINT "df_action_0" DEFAULT 'To Do' FOR "action_type";


                Though, you will more commonly see double quotes not used in this manner, and instead your DDL would be written as:



                CREATE TABLE action
                ( action INT IDENTITY(1,1)
                , name VARCHAR(250) NOT NULL
                , owner VARCHAR(50)
                , action_type VARCHAR(50) NOT NULL
                , due_date DATETIME
                , done_date DATETIME
                , successful BIT NOT NULL
                , job INT
                , contract INT
                , person INT
                , description VARCHAR(MAX)
                , deliverable VARCHAR(MAX)
                , outcome VARCHAR(MAX)
                , source VARCHAR(50)
                , notes VARCHAR(MAX)
                );

                ALTER TABLE action
                ADD CONSTRAINT df_action_0 DEFAULT 'To Do' FOR action_type;






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 3 hours ago

























                answered 8 hours ago









                scsimonscsimon

                1,5025 silver badges15 bronze badges




                1,5025 silver badges15 bronze badges




















                    Mark Kortink is a new contributor. Be nice, and check out our Code of Conduct.









                    draft saved

                    draft discarded


















                    Mark Kortink is a new contributor. Be nice, and check out our Code of Conduct.












                    Mark Kortink is a new contributor. Be nice, and check out our Code of Conduct.











                    Mark Kortink is a new contributor. Be nice, and check out our Code of Conduct.














                    Thanks for contributing an answer to Database Administrators Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f241410%2fsqlserver-add-a-default-value-for-a-column%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    199年 目錄 大件事 到箇年出世嗰人 到箇年死嗰人 節慶、風俗習慣 導覽選單