将数据从 Access 复制到 SQL

发布于 2024-08-12 07:11:57 字数 295 浏览 4 评论 0原文

我正在将现有的 Access 数据库迁移到具有 Web 前端的 SQL 数据库。我已使用 SQL Server 迁移工具成功将数据库复制到 SQL,并正在开发该应用程序。由于我不会在这里讨论的原因,我们不能只将 Access 前端链接到 SQL DB 并使用 SQL DB 作为单个数据源,因此 Access DB 仍在使用中并且数据正在更新。

我试图找到一种简单的方法来使用 Access DB 中的新数据更新 SQL 数据库中的数据。表结构等是相同的,所以我需要做的就是复制数据,是否有脚本或简单的方法来执行此操作?我真的不想每次需要更新时都运行迁移向导。

I am in the process of migrating an existing Access database to a SQL database with a web front-end. I have successfully copied the database to SQL using the SQL Server Migration tool and am working on developing the application. For reasons I won't go into here we cannot just link the Access front-end to the SQL DB and use the SQL DB as the single data source, so the Access DB is still in use and the data being updated.

What I am trying to find is a simple way to update the data in the SQL database with the new data in the Access DB. The table structure etc is the same so all I need to do is copy the data, is there a script or easy method to do this? I don't really want to have to run the migration wizard every time I need to do an update.

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

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

发布评论

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

评论(3

﹏雨一样淡蓝的深情 2024-08-19 07:11:57

我还建议使用 SQL Server 的链接表,但听上去这是你无法控制的。我希望这只是暂时的,以便用户可以在开发过程中继续使用 Access DB,而不是因为某些经理认为这种手动集成的系统是一个好主意“继续发展” 。

有一个更好的迁移到 SQL Server 的工具,称为 Sql Server 迁移Assistant (SSMA) 比 Access 中内置的“升迁向导”要好得多。您可以编写脚本以使任务可重复。

另一种方法是在 Access DB 所在的任何位置设置 SQL Server Express 版本并链接到该数据库,将其用作临时数据库。您可以将 SSEE 版本设置为复制订阅者,并同步您可以随时在该数据库和您的开发/生产数据库之间进行更改。对于用户来说,这将是透明的,您可以告诉管理层 Access DB 与开发/生产数据库完全分开。或者,如果您不愿意学习复制,则每次都复制数据库,但我认为复制可以使这一切变得更加简单。

I would also suggest using linked tables to the SQL server but by the sounds of it that's out of your control. I hope this is just temporary so the users can keep working on the Access DB while development is going on, and not because some manager thinks this kind of manually-integrated system is a good idea "going forward".

There is a better tool for migration to SQL server called Sql Server Migration Assistant (SSMA) that is much better than the "upsizing wizard" built into Access. You may be able to script that to make the task repeatable.

Another approach would be to set up an Express edition of SQL server wherever the Access DB lives and link to that, using it as a staging DB. You can set up the SSEE version as a replication subscriber, and synchronize changes between that and your development/production databases whenever you want. To the users it will be transparent and you can tell management that the Access DB is totally separate from the development/production databases. Or just copy over the database each time if you can't be bothered learning about replication, but I think replication could make it all much simpler.

深府石板幽径 2024-08-19 07:11:57

您可以通过 VBA 运行访问查询,在 SQL Server 中添加新记录并更新以前的记录。连接字符串与用于连接 SQL 表的字符串相同,正如我在这个粗略示例中指出的那样,因此您可以测试连接到相关表以获得合适的字符串:

Dim db As Database
Set db = CurrentDb

strConnect = db.TableDefs("dbo_test").Connect
strSQL = "UPDATE [" & strConnect & "].[test] As s " _
& "INNER JOIN TestAccess As a " _
& "ON s.ID=a.ID " _
& "SET s.Descr=a.Descr WHERE s.Descr<>a.Descr"
db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected

strSQL = "INSERT INTO [" & strConnect & "].[test] (ID, Descr) " _
& "SELECT a.ID, a.Descr FROM TestAccess As a " _
& "LEFT JOIN [" & strConnect & "].[test] s " _
& "ON s.ID=a.ID " _
& "WHERE s.ID Is Null"
db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected

You can run access queries through VBA that add new records and update previous records in the SQL Server. The connection string is identical to that used to connect an SQL table, as I indicate in this rough example, so you can test connect to the relevant table to obtain a suitable string:

Dim db As Database
Set db = CurrentDb

strConnect = db.TableDefs("dbo_test").Connect
strSQL = "UPDATE [" & strConnect & "].[test] As s " _
& "INNER JOIN TestAccess As a " _
& "ON s.ID=a.ID " _
& "SET s.Descr=a.Descr WHERE s.Descr<>a.Descr"
db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected

strSQL = "INSERT INTO [" & strConnect & "].[test] (ID, Descr) " _
& "SELECT a.ID, a.Descr FROM TestAccess As a " _
& "LEFT JOIN [" & strConnect & "].[test] s " _
& "ON s.ID=a.ID " _
& "WHERE s.ID Is Null"
db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected
陈年往事 2024-08-19 07:11:57

可以将 SQL Server 表链接到 Access,Access 表单可以正常输入数据,但实际上会进入 SQL Server。

Its possible to link SQL Server tables into Access where your Access forms can enter the data in as normal but it will actually be going into SQL Server.

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