Поделиться через


How to: Specify Default Values for Columns

For each column in your table, you can specify a default value that will be entered in the column if the user leaves it blank. If you do not assign a default value and the user leaves the column blank, then:

  • If you set the option to allow null values, NULL will be inserted into the column.

  • If you do not set the option to allow null values, the column will remain blank, but the user will not be able to save the row until they supply a value for the column.

For text strings, enclose the value in single quotation marks ('); do not use double quotation marks (") because they are reserved for quoted identifiers. For example, type: 98036 or 'Paris, France'.

If your entry in the Default Value field replaces a bound default (which is shown without parentheses), you will be prompted to unbind the default and replace it with your new default.

To enter a numeric default, you enter the number.

To enter a object/function you enter the name of the object/function with no single quotes around it.

To enter an alphanumeric default you enter the value with single quotes around it.

Note

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To specify a default value for a column

  1. In Server Explorer, right-click the table for which you want to specify default column values and choose Open Table Definition.

    The table opens in Table Designer.

  2. Select the column for which you want to specify a default value.

  3. In the Column Properties tab, enter the new default value in the Default Value or Binding property or select a default binding from the drop-down list.

Note

To enter a numeric default value, enter the number. For an object or function enter its name. For an alphanumeric default enter the value inside single quotes.

The new default value is assigned to the column in Table Designer after you click outside the grid cell or use the TAB key to move to another grid cell. It takes effect in the database when you save your changes in Table Designer.

See Also

Reference

Column Properties

Other Resources

Working with Columns