I have the following table in MySQL:
The id column is the primary key. I would like to remove the primary key from this table. How can I do this?
Thank you.
Run this query to remove the desired column:
ALTER TABLE 'tabela' DROP 'coluna';
I see that you are a beginner in PT StackOverflow , but do you really need to remove the primary key from your table? Well analyze your case, it is necessary to differentiate the records, so having something that makes them really unique, extremely important and necessary for UPDATES
and DELETES
, each case is a case, but before removing it, see if this really is needed as I already said.
And if you just want to make a SELECT
so that this column does not appear, it's simple, just send one: SELECT nome, profissao, nascimento, sexo, peso, altura, nacionalidade FROM tabela WHERE...
Finally, to just remove the primary key function you must execute these two querys:
//Você deve primeiro remover a propriedade de AUTO_INCREMENT e depois
//remover a chave primária
ALTER TABLE tabela MODIFY coluna INT NOT NULL;
ALTER TABLE tabela DROP PRIMARY KEY;
To return it as the primary key, just run:
ALTER TABLE tabela MODIFY coluna INT NOT NULL PRIMARY KEY AUTO_INCREMENT;