MySQL alter table command not working

I am trying to add a column to the table of existing users, but this will 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 is my command:

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

if I didnโ€™t say โ€œwrong,โ€ what am I doing wrong? Thanks

+4
source share
2 answers

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

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

+19
source

Move unsigned closer to tinyint :

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

Source: https://habr.com/ru/post/1379128/


All Articles