SQL Server String Constraints

I have a SQL Server database with a time column that can only be filled with the text "am" or "pm", and I cannot find a constraint that would allow me to do this.

+6
source share
1 answer

For an SQL server, you can use a restrictionCHECK that allows you to define a predicate that all rows must enter to enter a table. Like this:

ALTER TABLE TableName 
ADD CONSTRAINT CHK_ampm
CHECK(ColumnName IN ('am', 'pm'));
+15
source

All Articles