Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in SQL by (20.3k points)

Is there a way to specify, for example, 4 distinct values for a varchar column in MS SQL Server 2008?

For example, I need a column called Frequency (varchar) that only accepts 'Daily', 'Weekly', 'Monthly', 'Yearly' as possible values

Is this possible to set within the SQL Server Management Studio when creating the table?

1 Answer

0 votes
by (40.4k points)

You should try adding a check constraint on that column which can restrict values like this:

CREATE TABLE SomeTable

(

   Id int NOT NULL,

   Frequency varchar(200),

   CONSTRAINT chk_Frequency CHECK (Frequency IN ('Daily', 'Weekly', 'Monthly', 'Yearly'))

)

Related questions

Browse Categories

...