Modify foreign key for auto-increment

0

I have two tables in my bank

membro, membro_grupo, grupo

The grupo table has a column named id_grupo which is the primary key in this table. The membro table has a column named id_membro which is also a primary key. The membro_grupo table has two foreign keys, one call id_grupo and another call id_membro insert the code here, which makes association with the previous tables. But I made a small mistake when I created those tables. I forgot to put id_grupo of table grupo as auto-increment , and now I can not modify it. How do I make this exchange?

    
asked by anonymous 31.07.2016 / 19:05

2 answers

2

You can execute this directly in the sql query:

ALTER TABLE table_name MODIFY COLUMN column_name INT (6) auto_increment

Obviously, you need to change the names in bold.

The INT(6) stretch, change the number 6 by the amount you want. Represents the number of digits.

obs: If data already exists in this table, you should check if the already generated IDs are of the same type INT .

Setting initial value of auto increment

If you want to set a specific initial value for the auto increment, execute the query:

ALTER TABLE nome_da_tabela AUTO_INCREMENT = 5;

Change the number to the value you want.

    
31.07.2016 / 19:11
0

Try:

ALTER TABLE grupo MODIFY id_grupo INTEGER NOT NULL AUTO_INCREMENT;

    
31.07.2016 / 19:06