RubenHerman
RubenHerman

Reputation: 1854

SQL server query to add column with default value

I'm trying to change my SQL server database by adding another column to a table with 0 as a default value.

I thought this script worked in the past (for another table), but now I have an error when I try to execute the script

The script

ALTER TABLE Whatever
ADD WhateverColumn tinyint NOT NULL 
DEFAULT(0)

The errors

Anyone knows what's wrong with this?

Upvotes: 2

Views: 19841

Answers (4)

RubenHerman
RubenHerman

Reputation: 1854

As I expected, updating my SQL Server Management Studio to version 17.8.1 solved my issue.
After updating, I was able to run this command without any problem.

Upvotes: 0

Singh Amarjeet
Singh Amarjeet

Reputation: 45


@SammuelMiranda has just asked the same just now. It matters if you are using reserved keyword as table or column name also.
you can check this link Add a column with a default value to an existing table in SQL Server

Upvotes: 0

SammuelMiranda
SammuelMiranda

Reputation: 460

Maybe the "Whatever" you are using as the table name has unclosed quotation marks, or even the "WhateverColumn" (both that you place here as a token, i get it) my have this problem, or even the "WhateverColumn" actual name is a reserved word?

Upvotes: 1

Fahmi
Fahmi

Reputation: 37493

Try this:

ALTER TABLE Whatever
ADD WhateverColumn tinyint NOT NULL DEFAULT 0

Upvotes: 5

Related Questions