Error adding columns to MySql table

1

What could be wrong here? adding tables in MySQL (Simple query)

ALTER TABLE 'shaiyar1_almacen'.'sr_productos' ADD
'item_ali' varchar(255),
'item_cat' int(11),
'item_pack' int(11);

This is the error that returns me:

[Err] 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 'item_cat int(11), item_pack int(11)' at line 3

    
asked by Juan Carlos Villamizar Alvarez 13.12.2018 в 22:31
source

2 answers

3

Your complete query should include the word COLUMN you do it for each of the ones you want to add:

ALTER TABLE shaiyar1_almacen.sr_productos 
    ADD COLUMN item_ali varchar(255), 
    ADD COLUMN item_cat int(11), 
    ADD COLUMN item_pack int(11); 

If on the other hand you want to delete one then you will use the word DROP .

    
answered by 13.12.2018 / 22:47
source
1

As you can see in the ALTER TABLE documentation.

link

  

13.1.9 ALTER TABLE Syntax

ALTER TABLE tbl_name
   [alter_specification [, alter_specification] ...]
   [partition_options]

alter_specification:
   table_options
 | ADD [COLUMN] col_name column_definition
       [FIRST | AFTER col_name]

Then your query should be.

ALTER TABLE 'shaiyar1_almacen'.'sr_productos' -- tbl_name
ADD COLUMN 'item_ali' varchar(255), -- alter_specification
ADD COLUMN 'item_cat' int(11), -- alter_specification
ADD COLUMN 'item_pack' int(11) -- alter_specification
    
answered by 14.12.2018 в 02:47