Advertisement
Can somebody explain to me why SQL Server doesn't suppost enums? It seems like a perfectly acceptable thing to have, and they must have left it out for a reason... what is that reason?
Advertisement
Advertisement
-
Re: enums...
Fri, July 30, 2004 - 4:21 PMUmmm... because it's a database, and anytime you'd want to use an enum, you'd be more likely to look it up in a table anyway? -
-
Re: enums...
Fri, July 30, 2004 - 11:19 PMUmmm... I wouldn't be more likely to use a table anyway, Garrett. Esp if it were only for a couple values. enums create less programming overhead. There is no looking up another table to see if you can put a value in the field, and there's no looking up that table again to display the value.
Would you also say that people shouldn't store images in database because people are "more likely" not to?
-
-
Re: enums...
Tue, March 29, 2005 - 9:02 AMProbably because it's not in the ANSI-SQL standard. But that doesn't really answer your question, because now you need to know why it's not in the ANSI-SQL standard. Even if that's not a rhetorical question, I doubt anyone could give you a straight answer except for the designeers of the ANSI-SQL standard.
Really, instead of using enums, why don't you just use a VARCHAR() field?
I use a VARCHAR(4) field for a lot of the places I would normally use enums in other programming languages.
I use a lookup table like so:
CREATE TABLE tblStatusCodes
(
Code VARCHAR(4)
Desc VARCHAR(30)
CONSTRAINT PK_tblStatusCodes PRIMARY KEY CLUSTERED (StatusCode)
)
Now, in the table with actual user data in it is like so:
CREATE TABLE tblAccounts
(
...
StatusCode VARCHAR(4)
...
)
The tblAccounts.StatusCode column is a foreign key to tblStatusCodes
If you set up the referential integrity rules, this prevents spelling errors of a code when data is being inserted and updated. Also the tblStatusCodes table can be joined in for access to the Desc column whenever you need a human readable translation of whatever the code represents, say in the your app's forms or reports.