Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL alter table command does not work

Tags:

sql

mysql

I am trying to add a column to my existing users table but it does not work. I get:

ERROR 1064 (42000): 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 'unsigned default 0 after users_id' at line 1

Here's my command:

root@localhost:test> alter table users add column users_is_active tinyint(3) not null unsigned default 0 after users_id;

unless I didn't spell "not null" correctly, what am I doing wrong? Thanks

like image 901
Tech4Wilco Avatar asked Dec 01 '22 07:12

Tech4Wilco


1 Answers

alter table users add column users_is_active tinyint(3) not null unsigned default 0 after users_id;

TINYINT(3) UNSIGNED is the type. NOT NULL does not belong between TINYINT(3) and UNSIGNED. Instead say TINYINT(3) UNSIGNED NOT NULL (etc.).

like image 98
Kusalananda Avatar answered Dec 06 '22 17:12

Kusalananda