将数据从 Excel 加载到 SQL DB

发布于 2024-10-05 12:54:22 字数 198 浏览 0 评论 0原文

我在一张 xls 中有表格数据。我需要将此数据“更新”到 SQL DB 中的表中。

注意:

  1. xls 将仅包含将发生更改的列。 (例如,如果只有两列将发生更改,则 xls 中将只显示所有记录的这两列)

  2. 主键列将出现在 xls 中以供参考。

请帮我解决这个问题。

I have table data in a sheet of xls. I need to 'update' this data into a table in SQL DB.

Note:

  1. The xls will contain only the columns that will undergo change. (for example if only two columns will undergo changes, then only those two columns for all the records will be present in the xls)

  2. The primary key column will be present in xls for reference.

Please help me in solving this.

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

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

发布评论

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

评论(1

薄情伤 2024-10-12 12:54:22

如果这是一次性加载,那么将数据转换为 SQL 语句就非常容易了。假设您的工作表有两列(A 和 B),那么您可以将以下公式放入 C 列中:(

"update tablename set somecol=" & B1 & " where keycol=" & A1

根据需要对字符串的引号进行排序等)

接下来只需将公式复制到底部,然后复制 col 中的所有单元格C、粘贴到文本编辑器中并运行 SQL 工具。

如果您需要将其交给用户或经常运行,那么有很多很多方法可以做到这一点,这实际上取决于您可以使用的工具(Java、C#...)

If this is a one-off load then it is pretty easy to turn the data into SQL statements. Say your sheet has two columns (A & B) then you could put the following formula in column C:

"update tablename set somecol=" & B1 & " where keycol=" & A1

(sorting out quotes for strings, etc as appropriate)

Next just copy the formula down to the bottom, then copy all cells in col C, paste into a text editor and run into your SQL tool.

If you need to hand this over to users or run frequently then there are many, many ways to do this and it really depends on the tools at your disposal (Java, C#, ...)

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