Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server equivalent to MySQL enum data type?

People also ask

What is enum data type in SQL Server?

An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time. See Section 11.3. 1, “String Data Type Syntax” for ENUM type syntax and length limits.

Is enum valid data type in MySQL?

Many data types exist in MySQL to store different data into the database table. The enum data type is one of them. The full form of enum is an enumeration. When it is required to insert any particular value from the list of the predefined values into a field of a table, then an enum data type is used.

Should I use enum SQL?

Enum types are more convenient for coding. For infrequent releases, or if you often have new/deleted/changed values, use a database table. For static sets of values, or if you release code all the time, use an enum.

Is enum a string type in MySQL?

In MySQL, an ENUM is a string object whose value is chosen from a list of permitted values defined at the time of column creation. The ENUM data type provides the following advantages: Compact data storage.


It doesn't. There's a vague equivalent:

mycol VARCHAR(10) NOT NULL CHECK (mycol IN('Useful', 'Useless', 'Unknown'))

The best solution I've found in this is to create a lookup table with the possible values as a primary key, and create a foreign key to the lookup table.


IMHO Lookup tables is the way to go, with referential integrity. But only if you avoid "Evil Magic Numbers" by following an example such as this one: Generate enum from a database lookup table using T4

Have Fun!


CREATE FUNCTION ActionState_Preassigned()
RETURNS tinyint
AS
BEGIN
    RETURN 0
END

GO

CREATE FUNCTION ActionState_Unassigned()
RETURNS tinyint
AS
BEGIN
    RETURN 1
END

-- etc...

Where performance matters, still use the hard values.