开发者

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         开发者_如何学C    214  
3             147  
4             987  
5             561  

Thanks for any tips


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜