Populate data in SQL table

I have a table with two columns:

id_test1      id_test2  
1             Null  
2             Null  
3             Null  
4             Null  
5             Null  

How can I update or populate the id_test2 as below?

id_test1      id_test2  
1             256  
2             214  
3             147  
4             987  
5             561  

Thanks for any tips

Answers


UPDATE test_table 
SET id_test2 = 256
WHERE id_test1 = 1

You didn't include the name of your table so I used test_table instead. This can be used for each record and is pretty SQL agnostic for the most part, meaning the syntax SHOULD work for any RDBMS.


update myTable set id_test2 = 256 where id_test1 = 1
update myTable set id_test2 = 214 where id_test1 = 2

etc

edit:

Based on your comment, I'd just blow away the existing rows that contain the null values and insert new ones...

delete myTable
insert into myTable (id_test1,id_test2) values (1,256)
insert into myTable (id_test1,id_test2) values (1,214)
...
insert into myTable (id_test1,id_test2) values (2,256)
insert into myTable (id_test1,id_test2) values (2,214)

etc


Need Your Help

using $location.search on external link

javascript angularjs url

i try to simply modify a link parameter.

How to design a table if it has no candidate keys?

database relational-database normalization database-normalization

Currently in my database class we are discussing the relational model and normalization and so on. I have answered every question in my homework with ease but this one has thrown me for a loop: