在 SQL Server 和 CSV 文件之间同步

发布于 2024-08-08 09:20:22 字数 323 浏览 1 评论 0原文

同步 SQL Server 内的表(客户)和 Microsoft Excel 中 CSV 文件内的客户的更好方法是什么?

好的,这是解释: 我正在 C#.NET 2008 中开发一个软件,并在 SQL Server 2005 中创建一个名为 Customers 的表。该表的内容来自 CSV 文件,用户可以添加更多信息,因为 SQL 表比 CSV 文件具有更多字段。

第一次很简单..我只需为 CSV 文件中的每一行添加新内容。 但是,由于这些额外的字段,第二次我无法删除所有表以从头开始重新导入它,所以我需要一种可以自动验证 SQL 表和 CSV 文件中的每条记录的方法?或者我需要将记录一一处理?

What is the better way to synchronize a table (customers), inside SQL Server and the customers inside an CSV file in Microsoft Excel?

Ok, here is the explanation:
I am developing a software in C#.NET 2008, and I create a table named Customers in SQL Server 2005. The contents of this table comes from a CSV file and the user can add more information because the SQL Table has more fields than CSV file.

The first time is easy.. I just ADDNEW for each line in CSV file.
But, the second time I cannot delete all table to import it again from the beginning because of these extra fields, so I need a method that can verify each record inside my SQL Table and CSV file automatically? Or I need to treat the records one by one?

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

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

发布评论

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

评论(2

故事↓在人 2024-08-15 09:20:22

看看 SQL Server Integration Services,它可以完成您想做的所有事情,甚至更多。

或者,如果您确实想对其进行编码,那么我建议对 CSV 中的所有字段进行哈希处理,并使用它来比较每一行。不同的哈希 = 更改 = 更新的行。

Take a look at SQL Server Integration Services, it can do everything you want to do and way more.

Alternatively, if you do want to code it, then I suggest making a hash of all fields in the CSV and using that to compare each row. Different hash = change = updated row.

北方。的韩爷 2024-08-15 09:20:22

您可以将 CSV 表和额外信息分离到一张表和一个视图中。您将拥有一个表,它只是 CSV 文件本身的哑镜像,并且易于更新:

    TRUNCATE TABLE csvmirror;
    BULK INSERT csvmirror
    FROM 'P:\ath\to\csvfile.csv' WITH
    ( FIELDTERMINATOR = ','
    , ROWTERMINATOR = '\n' );

然后您在该“csvmirror”表上创建一个视图,该视图用数据库中的额外数据补充直接 csv 文件数据。

You could separate the CSV table and the extra information into one table and one view. You would have one table that is just a dumb mirror of the CSV file itself, and is easy to update:

    TRUNCATE TABLE csvmirror;
    BULK INSERT csvmirror
    FROM 'P:\ath\to\csvfile.csv' WITH
    ( FIELDTERMINATOR = ','
    , ROWTERMINATOR = '\n' );

Then you create a view on that 'csvmirror' table that supplements the direct csv-file data with your extra data from the database.

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