Changing field type Mariadb(Mysql)

Asked

Viewed 184 times

0

Staff created a table called entries in a test database. In it was inserting data from a.txt register file.

until then the id primary key when I created it was not auto_increment so for testing purposes I made a drop table and recreated the table with the field primary key auto_increment.

my doubt is:

the field id_faz is:

id_faz int unique not null primary key,

can change to:

id_faz int unique not null auto_increment primary key

without deleting and recreating a new table or losing data from the current table?

The table structure is this below:

create table cadastros( 
  `id_faz` int unique not null primary key, 
  `nome_faz` varchar(25) unique not null, 
  `data_compra` date not null 
);

1 answer

1


Use the query ALTER TABLE.

ALTER TABLE incremento CHANGE `id_faz` `id_faz` INT AUTO_INCREMENT;
  • worked cool I had seen this command on another site but was saying it duplicated the fields..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.