Generally, you'll need to have SQL scripts to do this. I tend to do this anyway, as it makes maintaining and versioning the database much easier in the long run.
The core idea is, upon running the setup program, you'll have a custom action to execute this script. The user executing your setup will need permissions to:
- Create a database
- Create tables and other database-level objects in the newly-created database
- Populate data
Your scripts will take care of all of that, though. You'll have a CREATE DATABASE
command, the appropriate CREATE SCHEMA
, CREATE TABLE
, CREATE VIEW
, etc. commands, and then after the schema is built, the appropriate INSERT
statements to populate the data.
I normally break this into multiple scripts, but YMMV:
- Create schema script
- "Common scripts" (one for the equivalent of
aspnet_regsql
for web projects, one with the creation of the Enterprise Library logging tables and procs)
- Create stored procedure script, if necessary (to be executed after the schema's created)
- Populate initial data script
For future maintenance, I create upgrade scripts where a single script typically handles the entire upgrade process.
When writing the scripts, be sure to use the appropriate safety checks (IF EXISTS
, etc) before creating objects. And I tend to make mine transactional, as well.
Good luck!