将数据填充到 SQL 表中

发布于 2024-09-13 23:22:35 字数 371 浏览 0 评论 0原文

我有一个包含两列的表:

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

如何更新或填充 id_test2 如下?

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

感谢您的任何提示

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落星ぅ辰 2024-09-20 23:22:35
UPDATE test_table 
SET id_test2 = 256
WHERE id_test1 = 1

您没有包含表的名称,因此我使用 test_table 代替。这可以用于每条记录,并且在很大程度上与 SQL 无关,这意味着该语法应该适用于任何 RDBMS。

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.

万水千山粽是情ミ 2024-09-20 23:22:35
update myTable set id_test2 = 256 where id_test1 = 1
update myTable set id_test2 = 214 where id_test1 = 2

编辑:

根据您的评论,我只是吹掉包含空值的现有行并插入新的......

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)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文