2
Run this query to remove the desired column:
ALTER TABLE `tabela` DROP `coluna`;
I see you’re a beginner in PT Stackoverflow, but is it really necessary to remove the primary key from your table? Analyze your case well, it is necessary to differentiate the records, so having something that makes them really unique, extremely important and necessary to UPDATES
and DELETES
, each case is a case, but before removing it, see if this is really necessary as I have already said.
And if you just want to make one SELECT
so that this column doesn’t appear, it’s simple, just send a: SELECT nome, profissao, nascimento, sexo, peso, altura, nacionalidade FROM tabela WHERE...
Finally, to just remove the primary key function you must perform 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;
For it to become a primary key, just run:
ALTER TABLE tabela MODIFY coluna INT NOT NULL PRIMARY KEY AUTO_INCREMENT;
To remove the primary key just by deleting the column? It is not possible to remove the key Primary without deleting the column?
– user131916
@Alexborges is like I said, do you want to take her off the table or just that she doesn’t show up on a
SELECT
? If it’s the second option, use what I said in the second paragraph– Woton Sampaio
@Alexborges Or do you just want her to stop being the primary key inside the table?
– Woton Sampaio
I want her to just stop being the primary key inside the table.
– user131916
@Alexborges I will modify the answer, see now
– Woton Sampaio
I get it. Thank you.
– user131916
When you run SQL: "ALTER TABLE table MODIFY column INT NOT NULL;", you remove the auto-increment from the column, this?
– user131916
@Alexborges yes, first the
AUTO_INCREMENT
must be removed for after the primary key function– Woton Sampaio
@Alexborges if this solves your problem, please mark the answer as accepted :), so other people who have the same question can also scan them further
– Woton Sampaio
I am having problems with my account. As soon as I solve, mark your answer as accepted. Thank you.
– user131916