Modify foreign key for auto-increment

Asked

Viewed 3,374 times

1

I have two tables in my bank

membro, membro_grupo, grupo

The table grupo has a column called id_grupo which is the primary key in this table. The table membro has a column called id_membro which is also a primary key. The table membro_grupo has two foreign keys, one call id_grupo and another call id_membro Enter the code here, which are associated with the previous tables. Only I made a small error when I created these tables. I forgot to put the id_grupo table grupo as auto-increment, and now I can’t change it. How do I make this change?

2 answers

3

You can run this directly in the sql query:

ALTER TABLE tableName MODIFY COLUMN column name INT(6) auto_increment

Obviously, you need to change the names in bold.

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

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

Setting auto increment start value

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

ALTER TABLE nome_da_tabela AUTO_INCREMENT = 5;

Exchange the number for the value you want.

0

Try:

ALTER TABLE grupo MODIFY id_grupo INTEGER NOT NULL AUTO_INCREMENT;

  • but don’t have to give LOCK before? I tried to use with LOCK but went wrong

  • Opá, then try without LOCK now.

  • is making the same mistake

  • Put in your question the error that gives.

Browser other questions tagged

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