SQL Server enum datatype problem
-
I want to declare a datatype like this:
create table abc ( days enum('sat','sun','mon') )
How can i do that? I know that mysql, oracle supports this type of database but what about sql server 2005? Also can i use user defined datatype for this kind of problem? if so then please tell me how. Thanks. TFR -
I want to declare a datatype like this:
create table abc ( days enum('sat','sun','mon') )
How can i do that? I know that mysql, oracle supports this type of database but what about sql server 2005? Also can i use user defined datatype for this kind of problem? if so then please tell me how. Thanks. TFRHi, there is no enum datatype in MS SQL. You may use a check constraint. Something like that:
CREATE TABLE tblTest ( ID INT PRIMARY KEY IDENTITY, ANormalColumn VARCHAR(10) DEFAULT ('') NOT NULL, RestrictedColumn INT CHECK (RestrictedColumn IN (1,2,3) )
The first of the following inserts is OK, while the latter throws an error:INSERT INTO tblTest (ANormalColumn, RestrictedColumn) VALUES ('A', 1) INSERT INTO tblTest (ANormalColumn, RestrictedColumn) VALUES ('B', 4)
-sa