Defining and Modifying Default Constraints

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Exploring and Changing the Database Structure > Designing Tables in Design Editor >

Defining and Modifying Default Constraints

The table design in the Design Editor provides an option in the context menu to define a standard value for a column. This command inserts the Default field into the column properties where you can then enter the actual standard value for the column.

 

 

To define a default value for a column:

1.In the Design Editor, right-click the column for which you want to define a default value and select Create Default Constraint from the context menu. In the column properties, the Default field is added to the General section and to the table design.

 

Alternatively, right-click the header of the Columns section in the table design and activate the Default Value column. Double-click that column in the row of the column for which you want to define a default constraint.

 

2.Enter the default value into the Default field (either in the Properties window or directly in the table design).

 

As always when making changes to the database structure, a change script is generated which must be executed in order to actually create the default constraint in the database.

 

Viewing default constraints

After you have executed the change script and unless a constraint with a higher priority has already been defined for that particular column, the default ic_default-value-column icon is displayed to the left of the column name in the Columns folder of the Online Browser and when you show the table in the Design Editor.

 

In the Online Browser, the name of the default constraint, which is composed of the column name plus the "Default_" prefix, shows up in the Constraints sub-folder of the respective column and is marked with the default constraint ic_default-constraint icon.

ob_default-constraint

The actual value of the default constraint, that is the default value that will be inserted into the column if a new row is added to the table, can be viewed in the Properties window of the respective column when displayed in the Design Editor.

 

Modifying default constraints

You can delete a default constraint or change its default value. Note that the default constraint is always deleted first and then recreated with the new value. The respective SQL statement is generated automatically in the Database Structure Change Script window if you change the default value in the Design Editor or in the Properties window.

prop_default-constraint

design_default-constraint

 

To change the default value of a column:

1.In the Online Browser, select the column and make sure that its properties are being displayed. Alternatively, display the Default Value field in the table design.
2.Edit the default value in the Default field of the General section, or in the appropriate row of the Default Value column in the table design, respectively.
3.Execute the change script.

 

 

To delete a default constraint:

1.In the Online Browser, select the column and expand its Constraints sub-folder.
2.Right-click the default constraint and select Delete from the context menu or select the constraint and press Del.
3.Execute the change script.

© 2019 Altova GmbH