Cannot add a new column (Incorrect syntax next to the keyword "COLUMN")

When i run this

ALTER TABLE agency
ADD COLUMN single_word varchar(100)

I get

Msg 156, Level 15, State 1, Line 2
Incorrect syntax next to the keyword "COLUMN".

I tried to remove COLUMN, but still the same problem.

+3
source share
3 answers

For TSQL Flavor, try this syntax:

ALTER TABLE agents
ADD [associated department] varchar(100)
+8
source

Depending on the database software you are using, if you want to have a space in the column name (which I would recommend against), you will have to avoid it.

For example, in MySQL you would use the back side (the character to the left of number 1 at the top of the keyboard):

ALTER TABLE agents
ADD COLUMN `associated department` varchar(100);

SQL Server [], (")

+3

I have the same problem when running this query on HeidiSQL. The solution is simple, modify the query like this:

ALTER TABLE "agency"
ADD "single_word" varchar(100)

just delete the keyword COLUMN.

+2
source

All Articles