Does SQL Server have an equivalent to MySQL's ENUM data type?


This works in MySQL version 8.0.12. The syntax is as follows.

create table yourTableName
(
yourColumnName enum(‘Value1’,Value2’,Value3’,......N)
default Value1’ or Value2 or Value3,..N
);

Set the enum type in MySQL with the following query.

mysql> create table EnumInMySQL
-> (
-> WebCRUD enum('CREATE','READ','UPDATE','DELETE')
-> default 'CREATE'
-> );
Query OK, 0 rows affected (0.60 sec)

The syntax of enum in SQL Server.

create table yourTableName
(
yourColumnName varchar(100)
CHECK(yourColumnName IN (‘Value1’,Value2’,Value3’,......N))
DEFAULT ‘Value1’ or Value2’ or Value3’,......N
);

Now the query is as follows for enum in SQL Server.

Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements