How do I insert a value into every record in a column of a table?

2

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'.

    
asked by anonymous 24.07.2017 / 18:48

4 answers

2

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
  • The UPDATE statement updates existing row columns in the table with names with new values.
  • The SET clause indicates which columns to modify and which values to provide.

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
    
24.07.2017 / 19:48
2
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

    
24.07.2017 / 19:34
2

Since the field you want to update is called campo :

UPDATE categoria
SET campo = 3
    
24.07.2017 / 18:53
2

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.

    
24.07.2017 / 20:03