76

I have a table table1 with three columns and a bunch of rows:

[key_col|col_a|col_b]

I want to update col_a with a set of values (i.e. leaving col_b unchanged), something like this:

INSERT INTO table1 AS t1 (key_col, col_a) VALUES ("k1", "foo"), ("k2", "bar");


But it doesn't work, how do I do this?

informatik01
  • 15,636
  • 10
  • 72
  • 102
Muleskinner
  • 13,657
  • 19
  • 57
  • 78

5 Answers5

119

You have to use UPDATE instead of INSERT:

For Example:

UPDATE table1 SET col_a='k1', col_b='foo' WHERE key_col='1';
UPDATE table1 SET col_a='k2', col_b='bar' WHERE key_col='2';
We're All Mad Here
  • 1,534
  • 3
  • 17
  • 43
Naveed
  • 40,370
  • 32
  • 94
  • 130
11
UPDATE table1 SET col_a = 'newvalue'

Add a WHERE condition if you want to only update some of the rows.

Chris Snowden
  • 4,898
  • 1
  • 24
  • 34
4

This is what I did for bulk update:

UPDATE tableName SET isDeleted = 1 where columnName in ('430903GW4j683537882','430903GW4j667075431','430903GW4j658444015')
radbyx
  • 9,002
  • 18
  • 79
  • 121
Abhay Shiro
  • 2,895
  • 2
  • 13
  • 23
2

if you want to fill all the column:

update 'column' set 'info' where keyID!=0;
Shawn Mehan
  • 4,433
  • 9
  • 29
  • 50
kairos
  • 29
  • 1
0

If you want to update data you should use UPDATE command instead of INSERT

piotrpo
  • 12,020
  • 7
  • 39
  • 58