Changing field type MariaDB (Mysql)

0

Staff created a table called records in a test database. In it I was doing the insertion of data of a file cadastros.txt

Until then the id primary key when I created it was not auto_increment so for test purposes I made a drop table and re-created the table with the primary key auto_increment field.

My question is:

the id_faz field is:

id_faz int unique not null primary key,

You can change to:

id_faz int unique not null auto_increment primary key

Without deleting and re-creating a new table or without losing the data of the current table?

The structure of the table is as follows:

create table cadastros( 
  'id_faz' int unique not null primary key, 
  'nome_faz' varchar(25) unique not null, 
  'data_compra' date not null 
);
    
asked by anonymous 02.01.2018 / 06:05

1 answer

1

Use the ALTER TABLE query.

ALTER TABLE incremento CHANGE 'id_faz' 'id_faz' INT AUTO_INCREMENT;
    
02.01.2018 / 06:12