Muokkaa

Jaa


Modify Check Constraints

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance

You can modify a check constraint in SQL Server by using SQL Server Management Studio or Transact-SQL when you want to change the constraint expression or the options that enable or disable the constraint for specific conditions.

In This Topic

Before You Begin

Security

Permissions

Requires ALTER permission on the table.

Using SQL Server Management Studio

To modify a check constraint

  1. In the Object Explorer, right-click the table containing the check constraint and select Design.

  2. On the Table Designer menu, click Check Constraints....

  3. In the Check Constraints dialog box, under Selected Check Constraint, select the constraint you wish to edit.

  4. Complete an action from the following table:

    To Follow these steps
    Edit the constraint expression Type the new expression in the Expression field.
    Rename the constraint Type a new name in the Name field.
    Apply the constraint to existing data Select the Check Existing Data on Creation or Enabling option.
    Disable the constraint when new data is added to the table or when existing data is updated in the table. Clear the Enforce Constraint for INSERTs and UPDATEs option.
    Disable the constraint when a replication agent inserts or updates data in your table. Clear the Enforce For Replication option.

    Note

    Some databases have different functionality for check constraints.

  5. Click Close.

  6. On the File menu, click Savetable name.

Using Transact-SQL

To modify a check constraint

To modify a CHECK constraint using Transact-SQL, you must first delete the existing CHECK constraint and then re-create it with the new definition. For more information, see Delete Check Constraints and Create Check Constraints.