Please enable JavaScript to view this site.

Altova DatabaseSpy 2021 Enterprise Edition

As with other database objects, there are several ways to create default constraints:

 

From the Online Browser

From the Design Editor

 

With most database types, you can add default constraints either when creating a new table, or later, by editing an existing table.

 

SQLite does not support adding default constraints to existing tables. You can create default constraints only at table creation time.

 

Adding default constraints from the Online Browser

The following instructions use a SQL Server database as model. The instructions are similar in other database kinds.

 

1.Right-click an existing column and select Create Default Constraint from the context menu. The column and all its parent objects change appearance to indicate that an uncommitted change dbs_ic_changed is in progress. Also, a structure change script is generated in the Database Structure Change Script Window.

dbs_default_constraint_02

2.In the Properties window, find the Default property and enter the default value or expression to be used by this constraint.

dbs_default_constraint_03

3.Click the Execute Change Script dbs_ic_execute_script button in the Database Structure Change Script window.

 

Adding default constraints from the Design Editor

Use either of the two approaches to add a default constraint from the Design Editor.

 

Approach 1:

 

1.Right-click a table in Online Browser and select Design Editor | Show in new Design Editor from the context menu.

2.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.

3.In the Properties window, find the Default property and enter the default value or expression to be used by this constraint.

4.Click the Execute Change Script dbs_ic_execute_script button in the Database Structure Change Script window.

 

Approach 2:

 

1.Right-click the title bar of the "Columns" section and select Default value from the context menu. A new "Default value" column appears on the table design.

2.Enter the default value or expression in the "Default Value" column.

dbs_default_constraint_04

3.Click the Execute Change Script dbs_ic_execute_script button in the Database Structure Change Script window.

© 2020 Altova GmbH