Del via


How to: Create SQL Server Express Edition Databases

When you install Microsoft SQL Server 2005 Express Edition with Visual Web Developer, you can use the Visual Studio data-management tools to create SQL Server Express Edition databases and populate them with database elements, such as tables, data, stored procedures, views, and so on.

For information about binding the data in your database to a data-bound control, see Binding to Databases.

Creating a Database for a Web Application

To create a database

  1. In Visual Web Developer, open Solution Explorer, right-click the App_Data folder of your Web application, and then click Add New Item.

    --or--

    If your application does not have an App_Data folder, right-click the root folder of your Web application, click Add ASP.NET Folder, and then click App_Data.

  2. Click SQL Database, type a name for the .mdf database file, and then click Add.

    Two files are created: DataBaseName.mdf and DataBaseName_log.ldf. Visual Web Developer automatically moves focus to the Data Connections section of the Server Explorer window and selects the newly created database.

To add a table to a database

  1. In the Data Connections section of the Server Explorer window, double-click (or expand) the database to which you want to add a table.

  2. Right-click the Tables folder and select Add New Table.

    The focus moves to the table definition panel for a new table.

  3. Add table columns, and specify the column name and data type of the new column, as well as whether the column allows nulls.

  4. Select the primary-key column (or press SHIFT+SELECT to select multiple columns for a multi-column primary key), right-click the selection, and then click Set Primary Key.

  5. Optionally, select an int (integer) column to specify as an identity column; and then, in the Column Properties panel for the column, double-click the Identity Specification section for the column and set (Is Identity) to Yes.

  6. Press CTRL+S to supply a table name and save the table. If you close the table definition panel without saving the table, you will be prompted to supply a table name, and the table will be automatically saved.

To add data to a table in a database

  1. In the Data Connections section of the Server Explorer window, double-click (or expand) the database that you want to work with and then double-click the Tables folder for that database.

  2. Right-click the table to which you want to add data and then click Show Table Data.

  3. In the data grid that appears, type the data that you want to place in the table, providing values for all of the required fields.

  4. When you are finished, select the next new row of the data grid. Visual Web Developer now writes the values for the populated row to the table.

See Also

Concepts

Using SQL Server Express with ASP.NET

Other Resources

Accessing Data with ASP.NET