Is it possible to create a column in Microsoft SQL Server that limits what can be added to column?

For example, I want to specify that an 'Email' column must contain an @ symbol in order to be valid. Is it possible to do this?

1 answer

  • answered 2018-03-13 21:12 Gordon Linoff

    You do this using a check constraint:

    alter table t add constraint chk_t_email check (email like '%@%' and email is not null);

    Of course, this is just an illustration. An email has many other rules as well. However, more comprehensive validation could be asked in another question.