2

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ctsinavos
  • 41
  • 4

1 Answers1

2

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'));
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459