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;
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
New contributor
add a comment |
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
New contributor
add a comment |
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
New contributor
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
sql-server constraint alter-table default-value
New contributor
New contributor
New contributor
asked 8 hours ago
Mark KortinkMark Kortink
61 bronze badge
61 bronze badge
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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;
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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;
add a comment |
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;
add a comment |
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;
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;
edited 3 hours ago
answered 8 hours ago
scsimonscsimon
1,5025 silver badges15 bronze badges
1,5025 silver badges15 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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