i am trying to add a constraint to a datatype of char(1)
i would like the user to only be able to enter Y
or N
or n
or Y
i clicked on check constraint in the CHECK CONSTRAINT EXPRESSION
window what am i supposed to enter?
i am trying to add a constraint to a datatype of char(1)
i would like the user to only be able to enter Y
or N
or n
or Y
i clicked on check constraint in the CHECK CONSTRAINT EXPRESSION
window what am i supposed to enter?
It is always better to make such changes manually, not via GUI.
ALTER TABLE YourTable
ADD CONSTRAINT CHK_YourTable_YourColumn_YesOrNo CHECK(YourCOlumn IN ('Y', 'N'))
Edit: GUI can issue suboptimal DDL, and with little practice you can be just as efficient with manual scripts as with GUI, and you know exactly what is happening. Also you really want to store all your DDL in version control, including the script for changes.
Using an ALTER TABLE statement:
ALTER TABLE dbo.YOUR_TABLE
ADD CONSTRAINT bool_check CHECK (LOWER(your_column) IN ('n', 'y')) ;
alter table TableName
add constraint CHK_TableName_ColumnName check (ColumnName in ('Y','N','y','n'))