'SQL Server equivalent to MySQL enum data type?
Does SQL Server 2008 have a a data-type like MySQL's enum?
Solution 1:[1]
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.
Solution 2:[2]
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!
Solution 3:[3]
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.
Solution 4:[4]
You can try something like
ALTER TABLE dbo.yourTable
ADD CONSTRAINT yourColumn CHECK(yourColumn IN('XL','L','M','S','XS'))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user1431422 |
| Solution 2 | Jony Adamit |
| Solution 3 | Taryn |
| Solution 4 | Jonan87 |
