A CHECK constraint enforces a rule on the values allowed in a column. It ensures that data entered into the column meets a specified condition. A default constraint specifies a default value for a column when no value is provided during an insert operation.
Database Explorer allows you to perform operations on CHECK or default constraints using the shortcut menu. Right-click a constraint in Database Explorer to access commands for specific tasks, such as creating, editing, or deleting constraints, or generating scripts for them.
1. In Database Explorer, right-click the Constraints node and select New Check Constraint.
2. On the Constraints tab of Table Editor, right-click the grid and select Add Check Constraint.
3. Configure the constraint properties.
4. Click Apply Changes.
1. In Database Explorer, right-click the constraint you want to edit and select Edit Check Constraint.
2. On the Constraints tab of Table Editor, update the CHECK constraint properties.
3. Click Apply Changes.
1. In Database Explorer, right-click the constraint you want to edit and select Edit Default Constraint.
2. On the Constraints tab of Table Editor, update the constraint properties.
3. Click Apply Changes.
To turn a constraint on, in Database Explorer, right-click the required constraint and select Enable.
Note
The Enable option is unavailable if the constraint is already turned on.
To turn a constraint off, in Database Explorer, right-click the required constraint and select Disable.
Note
The Disable option is unavailable if the constraint is already turned off.
1. In Database Explorer, right-click the required constraint and select Generate Script As, then select the statement type.
2. Select the output option:
For more information, see Generate the DDL and DML statements for database objects.
1. In Database Explorer, right-click the constraint you want to rename and select Rename, or press F2.
2. Enter the new constraint name.
3. Click Yes to confirm the renaming of the constraint.
To view the constraint properties, double-click the required constraint.
1. In Database Explorer, right-click the constraint you want to delete and select Delete, or press Delete.
2. Click Yes to confirm deleting the constraint, or No to discard the operation.
To view constraint properties, in Database Explorer, right-click the constraint and select Show Details.
Object Viewer opens, displaying detailed information about the constraint.
To update the constraint to reflect the latest changes, in Database Explorer, right-click the constraint or Constraints node and select Refresh, or press F5.
To open the Properties window, in Database Explorer, right-click the constraint and select Properties, or press F4.
1. In Database Explorer, right-click the Constraints node and select Filter.
2. In the Filter Settings dialog, configure the filter parameters.
3. Click OK to apply the filter.
Note
When you open the Constraints node, the number of objects it contains appears in parentheses next to the node name. This number changes based on your filter settings.
The following table describes the shortcut menu options, which appear when you right-click a specific constraint in Database Explorer.
| Name | Description |
|---|---|
| Edit Check Constraint | Opens the Constraints tab of Table Editor to modify an existing check constraint. |
| Edit Default Constraint | Opens the Constraints tab of Table Editor to modify an existing default constraint. |
| Enable | Turns on the selected check constraint. The Enable option is unavailable if the constraint is already turned on. The option is available for check constraints. |
| Disable | Turns off the selected check constraint. The Disable option is unavailable if the constraint is already turned off. The option is available for check constraints. |
| Source Control > Source Control Manager | Opens Source Control Manager, where you can track and manage changes to database schema and static data. When Source Control Manager is already open, this option refreshes it. |
| Source Control > Commit | Opens Source Control Manager with all local changes (if any) selected and ready to commit. When Source Control Manager is already open, this option refreshes it and selects all local database changes. |
| Source Control > Get Latest | Opens Source Control Manager with all remote changes (if any) selected, ready to pull using Get Latest. When Source Control Manager is already open, this option refreshes it and selects all remote database changes. |
| Generate Script As | Generates a script of the selected object using the CREATE, DROP, and DROP and CREATE statements. The script can be saved to a new SQL document or to a file, or copied to the clipboard. |
| Show Details | Opens Object Viewer to view object details. |
| Rename | Allows you to enter a new name for the check constraint. |
| Delete | Drops the selected object from the database. Shortcut: Delete |
| Refresh | Updates the object to reflect the latest changes. Shortcut: F5 |
| Properties | Opens the Properties pane to view the object information. Shortcut: F4 |
The following table describes the shortcut menu options, which appear when you right-click the Constraints node in Database Explorer.
| Name | Description |
|---|---|
| New Check Constraint | Opens the Constraints tab of Table Editor to add a check constraint. |
| Source Control > Source Control Manager | Opens Source Control Manager, where you can track and manage changes to database schema and static data. When Source Control Manager is already open, this option refreshes it. |
| Source Control > Commit | Opens Source Control Manager with all local changes (if any) selected and ready to commit. When Source Control Manager is already open, this option refreshes it and selects all local database changes. |
| Source Control > Get Latest | Opens Source Control Manager with all remote changes (if any) selected, ready to pull using Get Latest. When Source Control Manager is already open, this option refreshes it and selects all remote database changes. |
| Filter | Opens the Filter Settings dialog to control which check constraints should appear in the table in Database Explorer. |
| Show Details | Opens Object Viewer to view object details. |
| Refresh | Updates the object to reflect the latest changes. Shortcut: F5 |
Note
The Source Control shortcut menu is available only after you link the corresponding database to a source-control system.
In Database Explorer, hold down Ctrl and select multiple constraints. Then right-click the selection and select the required option.
The following table describes the shortcut menu options available for multiple constraints.
| Name | Description |
|---|---|
| Edit Default Constraint | Opens the Constraints tab of Table Editor to modify the selected default constraints. |
| Source Control > Source Control Manager | Opens Source Control Manager, where you can track and manage changes to database schema and static data. When Source Control Manager is already open, this option refreshes it. |
| Source Control > Commit | Opens Source Control Manager with all local changes (if any) selected and ready to commit. When Source Control Manager is already open, this option refreshes it and selects all local database changes. |
| Source Control > Get Latest | Opens Source Control Manager with all remote changes (if any) selected, ready to pull using Get Latest. When Source Control Manager is already open, this option refreshes it and selects all remote database changes. |
| Source Control > Link/Unlink Static Data | Opes the Source Control Link Static Data dialog that displays the tables whose data you want to link. |
| Edit Check Constraint | Opens the Constraints tab of Table Editor to modify the selected check constraints. |
| Enable | Turns on the selected check constraints. The Enable option is unavailable if the constraints are already turned on. |
| Disable | Turns off the selected check constraints. The Disable option is unavailable if the constraints are already turned off. |
| Generate Script As | Generates a script of the selected objects using the CREATE, DROP, and DROP and CREATE statements. The script can be generated to a new SQL document or to a file, or copied to the clipboard. |
| Delete | Drops the selected constraints from the database. Shortcut: Delete |
