I have the 'category' table and an 'id' column, with more than 100 records in that column.
How do I add a value to all of these records? In case the value would be '3'.
I have the 'category' table and an 'id' column, with more than 100 records in that column.
How do I add a value to all of these records? In case the value would be '3'.
A statement of type UPDATE - when you have records in the table and want to update them - is done as follows MySQL :
UPDATE nome_tabela SET campo = valor
In your case, to update the value of all records you simply remove the WHERE clause - used to filter / restrict some records - and then just > query similar to this:
UPDATE categoria SET campo = 3
update categoria set coluna='3' where coluna != '3'
I imagine it to be something like this. This only works on the console or if you disable mysql security because it does not leave for security
Since the field you want to update is called campo
:
UPDATE categoria
SET campo = 3
MySQL statement:
UPDATE Categoria
SET Campo = 3
This causes all values in the "Field" column to change to "3".
If there is a need to do this for specific lines, a conditional ( WHERE
) is required.
Hug.