开发者

create a blank database from a production database programmatically

For software testing purposes I would like to create a sterile clone (with all data blanked out) of the production database. This way I can run my unit tests on a known set of records every time. I am looking to try and do this programmatically within the unit tests themselves so I can ensure that the tables contain exactly the test data that I need for the functional tests.

I have found the following information relating to creating an Access database within C#. N开发者_如何学Cote: I know Access probably isn't the best solution, but its good enough!

What I would like to know, is there a way of using TableAdapters (perhaps) to replicate the production database schema (without any data) within a blank Access database file?


Do this:

  • create a copy of the access file; production -> test
  • connect to test database
  • enumerate all tables in the database
  • run DELETE * FROM [table] for all tables. run it several times if you have FK dependencies until there is no error - or TRUNCATE [table] as commented
  • compact the database


I do not have much experience with Access, but generally you would make a CREATE script for this purpose. Most database tools have a function for creating such a script. Such a script basically is a set of SQL statements that create all the objects (e.g. databases, views).

Searching for CREATE script and Access will give you some starting points.


I have bad experiences with Access as a production database. I won't recommend. Either go with SQLite or Firebird.

Secondly, yes you can use TableAdapters. You need to create two connections for each db. But I think there might be tools available to do this.

Edited **

How big is the database? For up to 4GB, Oracle Express Edition might help. Also, it will be easy to clone from Oracle to Oracle.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜