简体   繁体   中英

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#. Note: 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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM