ctsinavos
ctsinavos

Reputation: 41

SQL Server : Check Constraint expression

I have a check constraint in SQL Server that only allows 3 possible values, the expression is like this:

(([READ_WRITE] = 'H' OR [READ_WRITE] = 'W' OR [READ_WRITE] = 'R'))

I want to update this check constraint with a query because I don't have access to Management Studio.

Upvotes: 2

Views: 1037

Answers (1)

marc_s
marc_s

Reputation: 755371

You basically need to first drop the old check constraint:

ALTER TABLE dbo.YourTable
    DROP CONSTRAINT CHK_YourTable_ReadWriteValues;

(and fill in whatever actual names you have for your table and the check constraint on it), and then you need to create the new one:

ALTER TABLE dbo.YourTable
    ADD CONSTRAINT CHK_YourTable_NewReadWriteValues
        CHECK ([READ_WRITE] IN ('X', 'Y', 'Z'));

Upvotes: 2

Related Questions