ENUM Equivalent in SQL Server

An ENUM is a string object that has a value selected from a set of acceptable values that are explicitly listed in the column specification at the time the table is created.

However, SQL Server does not support this datatype, although MySQL does. You can get the same outcome by using the CHECK constraint.

Example:

MySQL:

CREATE TABLE tbOrders (
iOrderID INT,
OrderDate DATETIME,
OrderStatus ENUM(‘Delivered’, ‘Cancelled’, ‘Under Process’));

SQL SERVER:
CREATE TABLE tbOrders (
iOrderID INT,
OrderDate DATETIME,
OrderStatus VARCHAR(30) NOT NULL
CHECK (OrderStatus IN(‘Delivered’, ‘Cancelled’, ‘Under Process’)));

Hope this helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s