Defining a Default Constraint Print this Topic Previous Page Up One Level Next page

Home >  Tutorials > "ZooDB" Database > Defining Constraints >

Defining a Default Constraint

For some columns it may be useful to define a standard value. By defining a default constraint and setting the Result view options accordingly, this default is inserted automatically when a new row is added to the table in the Result view.


In this section of the tutorial, you will define a default constraint on the tblAnimalBirths table which sets the number in litter automatically to "1" for new rows that are added in the Result view.



To set a default number in litter in tblAnimalBirths:

1.In the table design, right-click column "NumberInLitter" and select Create Default Constraint from the context menu. The Default Value column appears in the table design. (If the Default Value column is not visible, click into the table design and it will resize properly.)


2.Double-click the field in the NumberInLitter row, type "1", and press Enter.
3.In the Database Structure Change Script window, click the Execute Change Script ic_execute-sql button to execute the change script and to commit the new default constraint to the database.


Testing the default constraint

When testing the default constraint you have just defined, make sure that the Initialize cells with default values option is enabled in the Result View options. Please note that this option is disabled by default.



To create a new row containing a default value:

1.Select the menu option Tools | Options (Ctrl+Alt+O) and select the Result View page of the Options dialog box.
2.Activate the Initialize cells with default values check box and click OK.
3.Right-click the table heading in the Design Editor and select SQL and Data | Edit Data from the context menu. A message box appears, click OK.
4.In the Result view, click the Append a new row ic_add_line button. The NumberInLitter column shows "1" in the new row.


© 2019 Altova GmbH