Creating a Check Constraint

Create a check constraint to limits the data that can be inserted into a table according to a specified condition.

Prerequisites 

Before you can create a check constraint, be sure that the data server containing the table for which you are creating a check constraint is running, and you created and established a connection to the data server.

  1. Expand the Tables folder.
  2. Right-click the table, and select New > Check Constraint from the context menu.

    The New Check Constraint wizard opens.

  3. Specify properties for the new check constraint.
    Field Description
    Check constraint name Enter a name for the check constraint in the text field.
    Filter column by name pattern Optionally enter a filter expression for columns to be displayed in the list of available columns. For example, * will list all columns for the specified table.
    Available columns This is a list of columns available for defining a check constraint. You can sort the list of columns by clicking on Column Name above the list. Move a column from the Available columns list to the Definition field using Paste>>.
    Definition This is an editable field for entering a boolean expression that defines the check constraint on the specified column values. The constraints can include:
    • A list of constant expressions introduced with in.
    • A set of conditions, which may contain wildcard characters, introduced with like. An expression can include arithmetic operations and Transact-SQL functions. The boolean expression cannot contain subqueries, aggregate functions, parameters, or host variables.
    Preview This field displays the DDL for creating the check constraint.
  4. Click Next, and specify save and execution properties for the check constraint.
    Field Description
    Generate script Select this option to generate DDL for the check constraint.
    Enter or select the parent folder Specify an existing project or create a new project in which to save the DDL.
    File name Enter the name of the file in which to store the DDL.
    Execute immediately Execute the DDL immediately. If you do not select this option, you must complete execution of the DDL later to create the check constraint.
    Open in editor after creation Create the check constraint, and then open it in the Table Schema Editor.
  5. Click Finish to create the check constraint.
Related concepts
Check Constraints
Related tasks
Editing Table Schema Data
Creating a Unique Constraint
Editing a Check Constraint
Dropping a Check Constraint
Creating a Unique Constraint
Creating a Column Check Constraint

Send your feedback on this help topic to Sybase Technical Publications: pubs@sybase.com

Your comments will be sent to the technical publications staff at Sybase, Inc. For product-related issues or technical support, contact Sybase Technical Support at 1-800-8SYBASE.