Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server string constraints

I have a SQL Server database with a time column which can only be filled with the text "am" or "pm" and I'm having trouble finding a constraint that would allow me to do this.

like image 807
LiamHarries Avatar asked Sep 26 '12 13:09

LiamHarries


1 Answers

For SQL server you can use CHECK constraint which allows you to define a predicate that all the rows must meet in order to enter the table. Like so:

ALTER TABLE TableName 
ADD CONSTRAINT CHK_ampm
CHECK(ColumnName IN ('am', 'pm'));
like image 192
Mahmoud Gamal Avatar answered Sep 25 '22 06:09

Mahmoud Gamal