Creating a table within a SQL Server database

After creating a database on the end user's computer, you'll want to define its schema by adding table definitions. WiX gives us a way to execute CREATE TABLE statements within the database that we're installing. In this recipe, we will add a table definition with a few basic fields.

Getting ready

Create a new setup project and name it NewTableInstaller.

How to do it...

To create a table, add a SqlString element that specifies the CREATE TABLE SQL statement:

  1. Add SqlExtension to the project by right-clicking on the References node in Solution Explorer and selecting OK after navigating to Add Reference... | Browse | WixSqlExtension.dll | Add.
  2. Add the SqlExtension namespace to the Wix element:
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" ...

Get WiX Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.