Stas Bichenko
Stas Bichenko

Reputation: 13283

Why does this ALTER TABLE query throw syntax error?

This is the query I'm using:

ALTER TABLE apartment ADD technical TEXT NOT NULL AFTER is_sale

Why does it produce a syntax error?

EDIT:

ALTER TABLE apartment ADD COLUMN technical TEXT NOT NULL AFTER is_sale still produces an error:

Error: (1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ALTER TABLE andreevka_apartment ADD COLUMN technincal TEXT NOT NULL AFTER' at line 1

Also doesn't validate: http://developer.mimer.com/validator/parser200x/index.tml#parser

Upvotes: 5

Views: 11040

Answers (5)

Stas Bichenko
Stas Bichenko

Reputation: 13283

It actually turned out that my query was copy-pasted from PhpMyAdmin and had some encoding issues. I pasted it into Notepad++, converted it to ANSI and it worked. Weird.

The syntax was perfectly fine.

Upvotes: 11

Sanjaya Liyanage
Sanjaya Liyanage

Reputation: 4746

ALTER TABLE apartment ADD technical TEXT NOT NULL AFTER is_sale is working fine and I tested it.I use HeidiSQL as client.Here no need of ADD COLUMN.check whether is_sale name is correct or apartment name is correct

Upvotes: 0

Fabio
Fabio

Reputation: 23510

You have a syntax error, to add column you should use COLUMN in sentence

ALTER TABLE apartment ADD COLUMN technical TEXT NOT NULL

EDITED

I think you cannot use AFTER with ALTER because it won't care of column order, it does not matter for storage or querying.

Upvotes: 1

whatsupbros
whatsupbros

Reputation: 802

Not sure it's allowed in MySQL, but in Oracle there's another syntax as well:

ALTER TABLE apartment ADD (technical TEXT NOT NULL AFTER is_sale);

Upvotes: -1

Suhel Meman
Suhel Meman

Reputation: 3852

use ADD COLUMN for adding new column

ALTER TABLE apartment ADD COLUMN technical TEXT NOT NULL AFTER is_sale

Upvotes: -1

Related Questions